在CentOS 7上安装Docker环境的方法与注意事项

2020-06-17 06:38:18易采站长站整理

Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker Hub account:
https://hub.docker.com

For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/

设置为自启动:

chkconfig docker on

调整docker数据目录:

把一个独立的数据分区设置为docker数据目录,需手工把docker原目录的数据都移到新的存储分区上去,然后以新的存储分区挂载到/var/lib/docker目录下。

service docker stop

拷数据及挂分区:

service docker start

4、创建一个专用的docker group

docker是需要使用root权限运行的,但仍然可以通过创建一个专用的用户组的方式,让一个具备sudo权限的普通用户管理docker服务。


# groupadd docker
# usermod -aG docker bjxtb

退出当前会话,重新登录后使用bjxtb直接管理docker:

$ docker run hello-world

运行一个 Docker 容器:


[root@localhost ~]# docker run -i -t centos /bin/bash
[root@dbf66395436d /]#

我们可以看到,CentOS 容器已经被启动,并且我们得到了 bash 提示符。在 docker 命令中我们使用了 “-i 捕获标准输入输出”和 “-t 分配一个终端或控制台”选项。若要断开与容器的连接,输入 exit。


[root@cd05639b3f5c /]# cat /etc/RedHat-release
CentOSLinux release 7.0.1406(Core)
[root@cd05639b3f5c /]#exit
exit
[root@localhost ~]#

我们还可以搜索基于 Fedora 和 Ubuntu 操作系统的容器。


[root@localhost ~]# docker search ubuntu
[root@localhost ~]# docker search fedora

显示当前正在运行容器的列表

您可能感兴趣的文章: