1. Environment and preparation work
ubuntu14.04
docker environment
(recommended tutorial :docker tutorial)
2. Building steps
1. Change the image source (because the default one is too slow, and the domestic one is faster)
sudo vim /etc/default/docker
Enter the following parameters:
DOCKER_OPTS="--registry-mirror=http://hub-mirror.c.163.com" //网易的,也可以使用daoClouds的
If it is a newly installed ubuntu environment, execute the following command (of course you can also use vi, or write directly)
sudo apt-get update //更新apt-get源,防止下载出错 sudo apt-get install vim -y //下载vim
2. Start docker and pull the registry image source
sudo service docker start //启动docker sudo docker pull registry //下载registry镜像
3. After downloading, check whether the download is successful
sudo docker images
4. Download After starting the container later, you can mount the data mapping in the container on the directory you specify. Here, /opt/data/registry is the directory where the host is stored
mkdir -p /opt/data/registry //创建目录 sudo docker run -d -p 5000:5000 -v /opt/data/registry:/var/lib/registry --name private_registry registry //启动容器 -d : 让容器可以后台运行 -p :指定映射端口(前者是宿主机的端口号,后者是容器的端口号) -v :数据挂载(前者是宿主机的目录,后者是容器的目录) --name : 为运行的容器命名
5. Then check whether the container is successfully started
sudo docker ps
6. Check the IP address of the host machine
ifconfig
7. Change the docker configuration file, Add your own private library address. Docker will load /etc/init/docker.conf when it starts. After reading the configuration file, you will find that it will load the /etc/default/docker file, so you only need to write the private library address to /etc /default/docker
sudo vim /etc/default/docker
8. Change DOCKER_OPTS to the following:
DOCKER_OPTS="--registry-mirror=http://hub-mirror.c.163.com --insecure-registry 192.168.147.129:5000"
The 5000 port must be added. The host accesses port 80 by default. If you don’t want to add it, you can start the container. When mapping the container's port 5000 to the host's port 80
9. After modification, restart the container and enable the registry service
sudo service docker restart //重启容器 sudo docker start private_registry //重启registry服务
The above five steps will build a private library.
3. Test
1. Pull an image and tag it (take busybox as an example, because busybox is relatively small)
sudo docker pull busybox:latest //拉取镜像 sudo docker tag busybox:latest 192.168.147.129:5000/busybox
2. Submit the tag image to your local image warehouse
sudo docker push 192.168.147.129:5000/busybox
3. Delete all images about busybox and view
sudo docker rmi busybox 192.168.147.129:5000/busybox //删除busybox镜像 sudo docker images //查看是否还有busybox镜像的信息
4. Pull busybox from the local image warehouse Mirror and view
sudo docker pull 192.168.147.129:5000/busybox sudo docker images //查看192.168.147.129:5000/busybox镜像的信息
If the above prompt appears, it means the pull is successful.
The above is the detailed content of How to build a local mirror warehouse. For more information, please follow other related articles on the PHP Chinese website!