本次实战先在CentOS上的Docker设置,再在Ubuntu上也设置,首先要实战的CentOS环境信息如下:
-
操作系统:CentOS Linux release 7.6.1810
-
Docker:1.13.1, build b2f74b2/1.13.1
设置
- 编辑此文件:/lib/systemd/system/docker.service
原来的设置:
ExecStart=/usr/bin/dockerd-current \
–add-runtime docker-runc=/usr/libexec/docker/docker-runc-current \
–default-runtime=docker-runc \
–exec-opt native.cgroupdriver=systemd \
–userland-proxy-path=/usr/libexec/docker/docker-proxy-current \
–init-path=/usr/libexec/docker/docker-init-current \
–seccomp-profile=/etc/docker/seccomp.json \
$OPTIONS \
$DOCKER_STORAGE_OPTIONS \
$DOCKER_NETWORK_OPTIONS \
$ADD_REGISTRY \
$BLOCK_REGISTRY \
$INSECURE_REGISTRY \
$REGISTRIES
把ExecStart=/usr/bin/dockerd-current \改为ExecStart=/usr/bin/dockerd-current -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock \,如下:
ExecStart=/usr/bin/dockerd-current -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock \
–add-runtime docker-runc=/usr/libexec/docker/docker-runc-current \
–default-runtime=docker-runc \
–exec-opt native.cgroupdriver=systemd \
–userland-proxy-path=/usr/libexec/docker/docker-proxy-current \
–init-path=/usr/libexec/docker/docker-init-current \
–seccomp-profile=/etc/docker/seccomp.json \
$OPTIONS \
$DOCKER_STORAGE_OPTIONS \
$DOCKER_NETWORK_OPTIONS \
$ADD_REGISTRY \
$BLOCK_REGISTRY \
$INSECURE_REGISTRY \
$REGISTRIES
修改完毕后保存退出;
2. 重新加载配并重启docker:
systemctl daemon-reload && systemctl restart docker
现在设置完毕了,来验证设置是否生效;
3. 先在本机试试docke服务是否正常,如下,本机访问一切正常:
[root@maven ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
bolingcavalry/nacosconfigdemo 1.0-SNAPSHOT ed524b78f80b 5 days ago 125 MB
bolingcavalry/nacosserver 0.0.1 9ab34ff860d8 3 weeks ago 156 MB
docker.io/openjdk 8u212-jdk-stretch 03b20c1fa768 6 weeks ago 488 MB
docker.io/openjdk 8u201-jdk-al
必看视频!获取2024年最新Java开发全套学习资料 备注Java
pine3.9 3675b9f543c5 4 months ago 105 MB
docker.io/fabric8/java-jboss-openjdk8-jdk 1.3 c9d7e2e7b917 20 months ago 436 MB
- 本机IP地址是192.168.121.131,现在尝试从另一台装有docker的机器上测试远程访问本机,命令是docker -H tcp://192.168.121.131:2375 images,如下所示,一切正常:
[root@centos7 ~]# docker -H tcp://192.168.121.131:2375 images
REPOSITORY TAG IMAGE ID CREATED SIZE
bolingcavalry/nacosconfigdemo 1.0-SNAPSHOT ed524b78f80b 5 days ago 125 MB
bolingcavalry/nacosserver 0.0.1 9ab34ff860d8 3 weeks ago 156 MB
docker.io/openjdk 8u212-jdk-stretch 03b20c1fa768 6 weeks ago 488 MB
docker.io/openjdk 8u201-jdk-alpine3.9 3675b9f543c5 4 months ago 105 MB
docker.io/fabric8/java-jboss-openjdk8-jdk 1.3 c9d7e2e7b917 20 months ago 436 MB
- 如果您觉得每次远程命令时都输入-H tcp://192.168.121.131:2375很麻烦,也可以将远程docker的IP信息存入环境变量DOCKER_HOST=“tcp://192.168.121.131:2375”,这样执行docker命令不带IP地址参数也会远程连接:
[root@centos7 ~]# export DOCKER_HOST=“tcp://192.168.121.131:2375”
[root@centos7 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
bolingcavalry/nacosconfigdemo 1.0-SNAPSHOT ed524b78f80b 5 days ago 125 MB
bolingcavalry/nacosserver 0.0.1 9ab34ff860d8 3 weeks ago 156 MB
docker.io/openjdk 8u212-jdk-stretch 03b20c1fa768 6 weeks ago 488 MB
docker.io/openjdk 8u201-jdk-alpine3.9 3675b9f543c5 4 months ago 105 MB
docker.io/fabric8/java-jboss-openjdk8-jdk 1.3 c9d7e2e7b917 20 months ago 436 MB
Ubuntu上的设置
Ubuntu上的设置和CentOS略有不同,这里也一并说明:
环境:
写在最后
还有一份JAVA核心知识点整理(PDF):JVM,JAVA集合,JAVA多线程并发,JAVA基础,Spring原理,微服务,Netty与RPC,网络,日志,Zookeeper,Kafka,RabbitMQ,Hbase,MongoDB,Cassandra,设计模式,负载均衡,数据库,一致性哈希,JAVA算法,数据结构,加密算法,分布式缓存,Hadoop,Spark,Storm,YARN,机器学习,云计算…
,JAVA基础,Spring原理,微服务,Netty与RPC**,网络,日志,Zookeeper,Kafka,RabbitMQ,Hbase,MongoDB,Cassandra,设计模式,负载均衡,数据库,一致性哈希,JAVA算法,数据结构,加密算法,分布式缓存,Hadoop,Spark,Storm,YARN,机器学习,云计算…
[外链图片转存中…(img-G14jMATL-1716438809504)]