run容器
docker run --detach --hostname gitlab.xxx.com --publish 444:443 --publish 81:80 --publish 23:22 --name gitlab --restart always --volume /srv/gitlab/config:/etc/gitlab --volume /srv/gitlab/logs:/var/log/gitlab --volume /srv/gitlab/data:/var/opt/gitlab 5d8ab6b06918
- --hostname :指定容器中绑定的域名,会在创建镜像仓库的时候使用到,这里绑定gitlab.xxx.com
- --publish:端口映射;容器内的443,80,22端口分别映射到宿主机的444,81,23端口
- --volume :挂载数据卷,映射到容器中去的容器外部存储空间
- 5d8ab6b06918 :镜像的ID
- --name 为容器指定一个名称
- -i:以交互模式运行容器,通常与 -t 同时使用
- -t: 为容器重新分配一个伪输入终端,通常与 -i 同时使用
- -d: 后台运行容器,并返回容器ID
当地的位置 | 容器的位置 | 作用 |
---|---|---|
/srv/gitlab/config | /etc/gitlab | 用于存储GitLab配置文件 |
/srv/gitlab/logs | /var/log/gitlab | 用于存储日志 |
/srv/gitlab/data | /var/opt/gitlab | 用于存储应用数据 |
docker常用命令
命令 | 作用 |
---|---|
docker ps | 查看正在运行的容器 |
docker ps -a | 查看全部容器 |
docker pull trainging/webapp | 拉取镜像 |
docker rmi |
删除images,通过image的id来指定删除谁 |
docker run | 启动一个容器 |
docker stop wizardly_chandrasekhar | 停止容器 |
docker start wizardly_chandrasekhar | 重启容器 |
docker rm wizardly_chandrasekhar | 移除容器(删除容器时,容器必须是停止状态,否则会报错) |
docker port bf08b7f2cd89 | 查看指定容器网络端口 |
docker exec -it 13bfd2asf /bin/bash | 进入容器 |
上传文件
docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH
OPTIONS说明:
-L :保持源目标中的链接
上传文件实例
docker cp /root/test.txt ecef8319d2c8:/root/
该命令的意思是将当前操作系统(CentOS)家目录(root)下的文件test.txt拷贝到容器id为ecef8319d2c8的家目录(root)文件夹下。
下载文件
docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
下载文件实例
docker cp ecef8319d2c8:/root/test.txt /root/