Install Docker CE
Set up the repository
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
Install Docker CE
sudo apt-get update
sudo apt-get install docker-ce
sudo docker run hello-world
Configure Docker to start on boot
$ sudo systemctl enable docker
Install docker-compose on Linux systems:
安装
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
or
pip install docker-compose
添加可执行权限
sudo chmod +x /usr/local/bin/docker-compose
测试
docker-compose --version
docker-compose开机启动
在 docker-compose.yml 中加入
restart: always
比如:
restart: always
volumes:
- "./nginx.conf:/etc/nginx/nginx.conf:ro"
当系统重启后,docker daemon重启会自动运行容器,前提是docker-compose要成功的运行一次。
镜像加速:
sudo nano /etc/docker/daemon.json
{
"registry-mirrors": ["https://bjtzu1jb.mirror.aliyuncs.com"]
}
参考:
https://docs.docker.com/config/containers/start-containers-automatically/
https://www.jianshu.com/p/84b6fe281b4d