本文主要是介绍在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
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>body {width: 35em;margin: 0 auto;font-family: Tahoma, Verdana, Arial, sans-serif;}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p><p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p><p><em>Thank you for using nginx.</em></p>
</body>
</html>
root@ubuntu:/dockerfile/df_test2#
这篇关于在Ubuntu中Dcoker构建镜像的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!