Prepare & Install Docker

🍩 Taste with Gitlab CI and Docker

1. Prepare the system environment

1.1. Configuring Proxy Server Access

1
2
3
export http_proxy=http://your_proxy_ip:port
export https_proxy=http://your_proxy_ip:port
export ALL_PROXY=http://your_proxy_ip:port

Optional: To enable all yum operations to use a proxy server, specify the proxy server details in /etc/yum.conf. The proxy setting must specify the proxy server as a complete URL, including the TCP port number. If your proxy server requires a username and password, specify these by adding proxy_username and proxy_password settings.

1
2
3
4
5
# The proxy server - proxy server:port number
proxy=http://your_proxy_ip:port
# The account details for yum connections (No need here)
# proxy_username=yum-user
# proxy_password=qwerty

1.2. Replace rhel mirror with centos mirror

First backup /etc/yum.repos.d/rhel-7-x86_64.repo

1
mv /etc/yum.repos.d/rhel-7-x86_64.repo /etc/yum.repos.d/rhel-7-x86_64.repo.backup

Download the corresponding version of the repo file and put it in /etc/yum.repos.d/

Run the following command to generate the cache

1
2
yum clean all
yum makecache

2. Install docker first

Only Centos 7 and above is supported (linux kernel version >= 3.10)

2.1. Set up the repository

Install required packages. yum-utils provides the yum-config-manager utility, and device-mapper-persistent-data and lvm2 are required by the devicemapper storage driver.

1
2
3
$ sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2

Use the following command to set up the stable repository. You always need the stable repository, even if you want to install builds from the edge or test repositories as well.

1
2
3
$ sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo

Optional: Enable the edge and test repositories. These repositories are included in the docker.repo file above but are disabled by default. You can enable them alongside the stable repository.

1
2
3
$ sudo yum-config-manager --enable docker-ce-edge

$ sudo yum-config-manager --enable docker-ce-test

2.2. Install docker ce

Install the latest version of Docker CE, or go to the next step to install a specific version:

1
$ sudo yum install docker-ce

Restart the Docker service:

1
2
3
systemctl restart docker
# or
service docker stop

Then move the entire /var/lib/docker directory to the destination path:

1
2
3
mkdir /opt/data/docker
mv /var/lib/docker /opt/data/docker
ln -s /opt/data/docker /var/lib/docker
咕咕咕