1

安装和基本命令

 2 years ago
source link: https://3wapp.github.io/Docker/%E5%AE%89%E8%A3%85%E5%92%8C%E5%9F%BA%E6%9C%AC%E5%91%BD%E4%BB%A4.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

1. docker 镜像打包

docker save new-image > /tmp/new-image.tar

导入tar包到本地docker镜像

docker load < /tmp/new-image.tar

2. install docker

# success for debian, ubuntu, kali
curl -sSL https://get.docker.com/ | sh

3. run 参数 镜像 创建后要运行的命令

指定端口映射(publish)。将主机的特定端口映射到容器的特定端口。格式为: -p 主机端口:容器端口 。

run -p <host_port>:<container_port>
e.g. run -p 8000:8000, run -p 192.168.0.9:80:80

如果有多个端口需要映射,可以写多次 -p 参数, docker run -p -p -p

将主机任意端口映射到容器使用的端口。

创建后在后台运行(detach),这样运行程序时就不会占用当前终端 。

设置容器运行时的环境变量,常用来注入一些需要动态改变的运行参数。

-i 和 -t 是两个不同的参数,前者以交互模式(interactive)运行命令,后者则为命令分配一个伪终端

挂载数据到容器内指定位置。如果没有指定挂载点,将仅仅生成一个可以被其他容器挂载的目录。可以多次使用 -v 来挂载多个路径。

# 添加一个数据卷
-v container_path

# 挂载当前主机的一个目录到容器中。如果容器内的挂载点不存在,则会自动创建。目录、文件都可以被挂载,
-v host_path:container_path

# 默认挂载卷是可读写的,可以在挂载时指定只读
-v host_path:container_path:ro

执行命令时所在的目录(working dir)。

当要运行的命令结束后立即删除容器,常用于测试。

  • --name

为容器分配一个名字,如果没有添加此参数,将生成一个随机名称。这个名称在操作容器时需要用到。

  • --link

格式为: --link 要连接的容器名:连接名

连接其他容器,并且为连接指定一个名称。docker 通过网桥来实现容器间的网络互联,因此如果创建容器时添加了此参数,则会自动在容器的 hosts 文件中加上被连接容器的 ip,ip 的别(域)名就是这里的连接名。不指定则默认为容器名称。

4. exec

docker run --name dubuntu -d ubuntu
docker exec -it dubuntu /bin/bash

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK