准备工作
- 启动一个容器:
- docker run -it --name ubuntu ubuntu:16.04 bash
- 然后依次执行命令:
- apt-get update
- apt-get install vim
- apt-get install net-tools
- apt install iputils-ping
- apt install apache2
- apt install apache2-utils
- apt install openssh-server
- apt install openssh-client
- apt install curl
- 修改sshd_config配置文件:
- vi /etc/ssh/sshd_config
将 PermitRootLogin 的值改为 yes
- vi /etc/ssh/sshd_config
- 退出容器,然后提交新镜像:
- docker commit -m “install tools about network” ubuntu ubuntu1604:v0.2
容器端口暴露
使用 -p 参数进行端口映射,格式如下:
- -p hostPort:containerPort 映射所有IP地址上的指定端口到容器内部
- -p ip:hostPort:containerPort 映射指定IP地址上的指定端口到容器内部
- -p ip:containerPort 映射指定IP地址上的任意端口到容器内部
一个宿主机端口映射到容器的例子
- 启动docker
- docker run -it --name web-server -p 80:80 ubuntu1604:v0.2