CentOS7 Install Docker and Docker Compose


CentOS7_Install_Docker_and_docker-compose

Install Docker

# Install Docker CE
## Set up the repository
### Install required packages.
yum install yum-utils device-mapper-persistent-data lvm2

### Add Docker repository.
yum-config-manager \
  --add-repo \
  https://download.docker.com/linux/centos/docker-ce.repo

yum update && yum install docker-ce-18.06.2.ce
# If you are going to use local rpm to install Docker, follow steps below:
# First copy docker rpms from 10.20.0.198:/root/rpms/docker
# mkdir -pv /root/rpms/docker && \
# scp -r root@10.20.0.198:/root/rpms/docker /root/rpms/docker && \
# cd /root/rpms/docker && \
# yum localinstall ./*.rpm

# Add your user to the docker group with the following command.
usermod -aG docker $(whoami)

## Create /etc/docker directory.
mkdir -pv /etc/docker

# Setup daemon.
cat > /etc/docker/daemon.json <<EOF
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "20m"
  },
  "storage-driver": "overlay2",
  "storage-opts": [
    "overlay2.override_kernel_check=true"
  ]
}
EOF

mkdir -p /etc/systemd/system/docker.service.d

# Don't forget to set SELinux to permissive:
# Set SELinux in permissive mode (effectively disabling it)
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

# Set Docker to start automatically at boot time:
systemctl enable docker.service

# Restart Docker
systemctl daemon-reload
systemctl restart docker

# Check docker daemon info
docker info

# Check if docker runs normally
docker run --rm --name=hello-world hello-world

Install docker-compose

  1. Run this command to download the current stable release of Docker Compose:

    sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

  2. Apply executable permissions to the binary:

    sudo chmod +x /usr/local/bin/docker-compose

    Note: If the command docker-compose fails after installation, check your path.
    You can also create a symbolic link to /usr/bin or any other directory in your path.

    For example:

    sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

  3. Test the installation.

    $ docker-compose --version
    docker-compose version 1.24.1, build 1110ad01

文章作者: 少年G
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 少年G !
评论
 上一篇
个人用-常用命令-笔记 个人用-常用命令-笔记
个人用的常用命令笔记,主要包括Linux、Docker、kubectl等工具的命令和代码块。
2019-09-20
下一篇 
分析Dockbix的Dockerfile--通用的多程序镜像的设计思路 分析Dockbix的Dockerfile--通用的多程序镜像的设计思路
一般来说一个软件的镜像的最后由`ENTRYPOINT`和`CMD`来构成,有的镜像可能没有`ENTRYPOINT`, `ENTRYPOINT`和`CMD`的主要区别在于即使你在运行镜像时指定了“命令” (e.g. `docker run nginx echo "test"`的`echo "test"`部分就是“命令”),`ENTRYPOINT`中 指定的命令(e.g. `ENTRYPOINT entrypoint.sh`)也不会被忽略。 总的来说,可以把以下几条规则当做创作Dockerfile的thumb rules: - `RUN`: 用来安装软件或添加依赖,因为`RUN`会创建一层`layer`。 - `ENTRYPOINT`: 用来指定该镜像为可执行程序,并且指定一个一个脚本用来初始化基础环境( e.g. 创建镜像运行时所使用的用户、加载程序的依赖、初始化环境变量等。)。 - `CMD`: 用来运行软件。 - `ENTRYPOINT`与`CMD`结合使用: 在`ENTRYPOINT entrypoint.sh`中初始化环境,最后执行`exec "$@"`,以此来继续执行 `CMD`中的内容。
2019-09-16
  目录