Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Pull complete Digest: sha256:c3b4ada4687bbaa170745b3e4dd8ac3f194ca95b2d0518b417fb47e5879d9b5f Status: Downloaded newer image for hello-world:latest
Hello from Docker! This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.
To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/
For more examples and ideas, visit: https://docs.docker.com/get-started/
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial universe deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties deb http://archive.canonical.com/ubuntu xenial partner deb-src http://archive.canonical.com/ubuntu xenial partner deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
# 将本目录下的sources.list作为容器的一个文件 ADD sources.list /root/sources.list # 使用阿里Ubuntu源,更新快 RUN mv /etc/apt/sources.list /etc/apt/sources.list_bak RUN cp /root/sources.list /etc/apt/sources.list
RUN apt-get update # 安装vim RUN apt-get install -y vim # 安装ssh RUN apt-get install -y openssh-server RUN mkdir -p /var/run/sshd # 修改root密码,便于远程登录 RUN echo root:Software2020 chpasswd # 配置ssh可以使用root登陆 RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config # 复制配置文件到相应位置,并赋予脚本可执行权限 ADD run.sh /run.sh RUN chmod 755 /run.sh
# 开放22端口 EXPOSE 22 #设置自启动命令 CMD ["/run.sh"]
4.编译docker镜像
现在已经完成上面的步骤,那我们的当前文件夹应该有三个文件:
1 2
root@Ubuntu:~/docker# ls dockerfile run.sh sources.list
现在在当前目录执行镜像编译命令:
1
docker build -t base_env:16.04 .
如果一切OK的话,本地镜像中会自动出现我们的base_env:16.04镜像:
1 2 3
root@Ubuntu:~/docker# docker images REPOSITORY TAG IMAGE ID CREATED SIZE base_env 16.04 ec9e3882279b 20 minutes ago 261MB
root@Ubuntu:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 83ef1192a91d base_env:16.04 "/run.sh" 3 seconds ago Up 2 seconds 0.0.0.0:12306->22/tcp quectel