Centos7 上手 Docker 容器及 docker-compose
我们非常重视原创文章,为尊重知识产权并避免潜在的版权问题,我们在此提供文章的摘要供您初步了解。如果您想要查阅更为详尽的内容,访问作者的公众号页面获取完整文章。
1. Uninstalling Old Version of Docker
Older versions of Docker, known as docker
or docker-engine
, need to be uninstalled along with their dependencies using the command
yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
. Additionally, Docker images, containers, configuration files, etc., should be removed with rm -rf /var/lib/docker
.
2. Installing New Version of Docker
For managing yum repositories, yum-utils
is installed using yum -y install epel-release.noarch yum-utils
. The yum repository is then set up with either the official Docker source, which is slower, or the recommended Aliyun source. The commands yum-config-manager --add-repo
followed by the repository URLs are used for this purpose.
Installation of the latest Docker Engine and containerd is done via the command yum install docker-ce docker-ce-cli containerd.io
. To install a specific version of Docker Engine-Community, one can list the available versions with yum list docker-ce --showduplicates | sort -r
and install the desired version using its complete package name.
3. Starting and Stopping Docker
Docker is started with systemctl start docker
. After installation, to use a faster, domestic mirror for image downloading, the image repository needs to be switched following instructions provided by Aliyun. Docker can be stopped using systemctl stop docker
, which may prompt a warning due to Docker's auto-activation mechanism. To prevent Docker from waking up automatically, one should stop the docker.socket
after stopping the Docker service. Restarting Docker is done with systemctl restart docker
.
4. docker-compose
docker-compose
is a tool for defining and running multi-container Docker applications. It allows the use of a YAML file to configure services, which can then be created and managed with a single command. Instead of shell scripts, services are defined in the configuration file, and docker-compose
scripts are used to start, stop, and restart both the application and its services.
For installing docker-compose, the binary is downloaded and permissions are set with chmod +x
, then a symbolic link is created. Successful installation can be verified with docker-compose --version
. Alternatively, docker-compose can also be installed using pip by downloading the pip rpm package, installing pip, upgrading it, and then installing docker-compose.
Reference: https://docs.docker.com/engine/install/centos/
想要了解更多内容?