在Ubuntu中Dcoker构建镜像



构建镜像



通过Dockerfile创建一个ubuntu带nginx的镜像

root@ubuntu:~# mkdir -p /dockerfile/df_test2
root@ubuntu:~# cd /dockerfile/df_test2/
root@ubuntu:/dockerfile/df_test2# vim Dockerfile
root@ubuntu:/dockerfile/df_test2# cat Dockerfile 
# 设置基本的镜像,后续命令都以这个镜像为基础  
FROM ubuntu
# 作者信息  
MAINTAINER  shangwu  
# RUN命令会在上面指定的镜像里执行任何命令  
RUN apt-get update
RUN apt-get install -y nginx


#暴露ssh端口
EXPOSE  80  
root@ubuntu:/dockerfile/df_test2# docker images 
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubuntu-nginx        v1                  8377a82bd88d        6 minutes ago       232.8 MB
ubuntu              latest              dc8dd8718e57        10 days ago         119.2 MB





执行Dockerfile

root@ubuntu:/dockerfile/df_test2# docker build -t='ubuntu-nginx-df_test2' .
root@ubuntu:/dockerfile/df_test2# docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubuntu-nginx-df_test2   latest              266559c6bc7f        2 minutes ago       214.3 MB
ubuntu-nginx            v1                  8377a82bd88d        13 minutes ago      232.8 MB
ubuntu                  latest              dc8dd8718e57        10 days ago         119.2 MB
root@ubuntu:/dockerfile/df_test2# 







通过刚刚创建的进行启动一个容器=nginx-web3

root@ubuntu:/dockerfile/df_test2# docker run -d --name=nginx-web3 -p 80 ubuntu-nginx-df_test2 nginx -g "daemon off;"
ffd39288dbdcd6af18beba89278e80e88d464e9e34388c4d61f181dfe3081d1c
root@ubuntu:/dockerfile/df_test2# docker ps
CONTAINER ID        IMAGE                          COMMAND                CREATED             STATUS              PORTS                   NAMES
ffd39288dbdc        ubuntu-nginx-df_test2:latest   "nginx -g 'daemon of   7 seconds ago       Up 6 seconds        0.0.0.0:32771->80/tcp   nginx-web3          
892ba90fd7f0        ubuntu-nginx:v1                "nginx -g 'daemon of   12 minutes ago      Up 12 minutes       0.0.0.0:32770->80/tcp   nginx-web2          
fbfacadb6dfe        ubuntu-nginx:v1                "nginx -g 'daemon of   13 minutes ago      Up 13 minutes       80/tcp                  nginx-web1          
666dc69dc786        ubuntu:latest                  "/bin/bash"            8 hours ago         Up About an hour    0.0.0.0:32769->80/tcp   web                 
root@ubuntu:/dockerfile/df_test2# curl http://127.0.0.1:32771



Welcome to nginx!



Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

root@ubuntu:/dockerfile/df_test2#


你可能感兴趣的:(【Docker】Ubuntu)