docker
目前docker官网已经无法登录,但是还可以从清华镜像站(https://mirrors.tuna.tsinghua.edu.cn/docker-ce/)下载。
使用方法可以参考早期文章《docker笔记》
docker-compose
部署
可以从Github下载不同版本的二进制文件,例如docker-compose-linux-x86_64。
下载完成后,将二进制文件复制入路径,例如/usr/local/bin,增加可执行权限和创造软链接
mv docker-compose-linux-x86_64 /usr/local/bin/
chmod +x /usr/local/bin/docker-compose-linux-x86_64
ln -s /usr/local/bin/docker-compose-linux-x86_64 /usr/bin/docker-compose
测试能否正常使用
docker-compose version
配置
一个配置文件test.yml示例如下:
version: '3'
services:
test-container:
image: test-image:1.0
networks:
- test-net
extra_hosts:
- "host1: 1.1.1.1"
- "host2: 2.2.2.2"
container_name: test-container-1
volumes:
- /var/log/test-container/test-container.log:/api/test-container.log
restart: always
ports:
- "5000:5000"
dns: 8.8.8.8
environment:
ENV1: ABC
ENV2: DEF
networks:
test-net:
external: true
该示例中,容器会被命名为test-container-1,使用已有的容器网络test-net,并进行了修改hosts文件、挂载卷、端口映射、配置DNS、配置环境变量操作。
命令
- 使用
docker-compose -f test.yml config
命令检查配置文件有无错误。 - 使用
docker-compose -f test.yml up
命令启动容器即可,或用docker-compose -f test.yml up -d
后台执行。 - 使用
docker-compose -f test.yml stop
命令停止容器,docker-compose -f test.yml down
命令则会停止并删除容器 - 使用
docker-compose -f test.yml ps
命令可以查看容器状态