1. Mirror acceleration
1) Register an account
https://dev.aliyun.com/search.html
Alibaba Cloud will automatically assign the user an address of an image accelerator. After logging in, go to "Administration Center" --> "Accelerator", which contains the address of the image accelerator assigned to you and the usage instructions for each environment.
Mirror accelerator address: https://xxxxx.mirror.aliyuncs.com
2) Execute the following command on the docker host
# The system requires CentOS 7 or above and Docker 1.9 or above.
sudo cp -n /lib/systemd/system/docker.service /etc/systemd/system/docker.service sudo sed -i "s|ExecStart=/usr/bin/docker-current daemon|ExecStart=/usr/bin/docker-current daemon --registry-mirror=https://xxxxx.mirror.aliyuncs.com|g" /etc/systemd/system/docker.service sudo systemctl daemon-reload sudo service docker restart
Note: Here you should pay attention to the docker startup command in the /etc/systemd/system/docker.service file. I installed docker version 1.10, and the startup command is /usr/bin/docker-current, so execute the second sed command to use docker-current.
3) When downloading the image, just pull it normally, for example: docker pull centos, docker will use the Alibaba Cloud image for acceleration.
2. Enable remote access
Reference: http://blog.csdn.net/wangtaoking1/article/details/44494847
1) Add remote access configuration
sudo vi /etc/sysconfig/docker-network
# /etc/sysconfig/docker-network DOCKER_NETWORK_OPTIONS="-H unix:///var/run/docker.sock -H 0.0.0.0:2375"
2) restart docker
sudo systemctl daemon-reload
sudo service docker restart
3) Firewall opens port 2375
4) Description: Check /etc/systemd/system/docker.service to find:
The command to start the docker service is:
ExecStart=/usr/bin/docker-current daemon --registry-mirror=https://xxxx.mirror.aliyuncs.com \ --exec-opt native.cgroupdriver=systemd \ $OPTIONS \ $DOCKER_STORAGE_OPTIONS \ $DOCKER_NETWORK_OPTIONS \ $ADD_REGISTRY \ $BLOCK_REGISTRY \ $INSECURE_REGISTRY
The $ parameters that follow are configured in the following files:
EnvironmentFile=-/etc/sysconfig/docker EnvironmentFile=-/etc/sysconfig/docker-storage EnvironmentFile=-/etc/sysconfig/docker-network
开启远程访问的参数一般为$DOCKER_NETWORK_OPTIONS,其配置在/etc/sysconfig/docker-network中,我们也可以自己增加一些参数,然后加到启动命令的后面。
5)使用说明:
开启远程访问后,可以在其它docker主机上对该机器进行远程访问,比如查看远程docker主机的镜像:
sudo docker -H 10.211.55.9:2375 images
参数说明:
-H 10.211.55.9:2375:远程docker主机的ip地址和端口
如果使用maven的话,也可以使用maven插件实现自动部署镜像的功能,比如使用Dockerfile自动构建:
<plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.2.9</version> <configuration> <imageName>${project.name}:${project.version}</imageName> <dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory> <skipDockerBuild>false</skipDockerBuild> <dockerHost>http://10.211.55.9:2375</dockerHost> <resources> <resource> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jar</include> </resource> </resources> </configuration> </plugin>
imageName:生成的镜像名称 dockerDirectory:Dockerfile工作目录 skipDockerBuild:不跳过构建,就是执行镜像构建 dockerHost:docker的主机地址 resource:拷贝到Dockerfile工作目录的资源,此处是将生成的jar文件拷贝过去,本例中此处生成的jar文件为config-1.0.0-SNAPSHOT.jar
FROM java:8 VOLUME /tmp RUN mkdir /app ADD config-1.0.0-SNAPSHOT.jar /app/app.jar ADD runboot.sh /app/ RUN bash -c 'touch /app/app.jar' WORKDIR /app RUN chmod a+x runboot.sh EXPOSE 8888 CMD /app/runboot.sh
java -Djava.security.egd=file:/dev/./urandom -jar /app/app.jar
-Djava.security.egd=file:/dev/./urandom:java随机数生成策略,采用非阻塞方式
mvn clean package docker:build -DskipTests
mvn clean package docker:build -DskipTests -X :打印debug信息