$ curl -fsSL get.docker.com -o get-docker.sh $ sudo sh get-docker.sh
<output truncated>
If you would like to use Docker as a non-root user, you should now consider adding your user to the "docker" group with something like:
sudo usermod -aG docker your-user
Remember that you will have to log out and back in for this to take effect!
WARNING: Adding a user to the "docker" group will grant the ability to run containers which can be used to obtain root privileges on the docker host. Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface for more information.
验证Docker CE
通过运行hello-world 镜像 验证是否正确安装了Docker CE
1
$ sudo docker run hello-world
1 2 3
root@souyunku:~# sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest f2a91732366c 7 weeks ago 1.85kB
二、运行 Redis 镜像
1.运行镜像
1
$ docker run --name redis-6379 -p 6379:6379 -d redis
root@souyunku:~# docker images redis REPOSITORY TAG IMAGE ID CREATED SIZE redis latest 1e70071f4af4 4 weeks ago 107MB
查看镜像进程
1 2 3
root@souyunku:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2f1f20f672e3 redis "docker-entrypoint.s…" 14 seconds ago Up 14 seconds 0.0.0.0:6379->6379/tcp redis-6379
查看容器进程
1 2 3
root@souyunku:~# docker container ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2f1f20f672e3 redis "docker-entrypoint.s…" 7 minutes ago Up 7 minutes 0.0.0.0:6379->6379/tcp redis-6379
3.测试Redis服务
通过 redis-cli 连接Redis 服务,测试存储数据
1 2 3 4 5 6 7
root@souyunku:~# docker run -it --link redis-6379:redis --rm redis redis-cli -h redis -p 6379 redis:6379> set count 1 OK redis:6379> get count "1" redis:6379> exit root@souyunku:~#
root@souyunku:/opt# docker images souyunku-app REPOSITORY TAG IMAGE ID CREATED SIZE souyunku-app v1 8ec4e85a0f05 2 minutes ago 681MB
3.运行镜像
后台守护进程运行,然后把容器端口映射到,外网端口80
1 2
root@souyunku:/opt# docker run --name MySpringBoot -d -p 80:80 souyunku-app:v1 e68d438603619e363883d4eae65d3918e1c3e00f867731207bccf06f5690dc64
4.查看进程
查看容器进程,可以看到redis 在 6379端口,MySpringBoot 项目在 80端口
1 2 3 4
root@souyunku:/opt# docker container ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e68d43860361 souyunku-app:v1 "java -Djava.securit…" About a minute ago Up About a minute 0.0.0.0:80->80/tcp MySpringBoot 0f9646171edd redis "docker-entrypoint.s…" 39 minutes ago Up 39 minutes 0.0.0.0:6379->6379/tcp redis-6379