Dockerfile 在创建的镜像中安装命令

wangshumin@machine1:~/sinatra$ ll
总用量 12
drwxrwxr-x  2 wangshumin wangshumin 4096 3月   8 11:41 ./
drwxr-xr-x 27 wangshumin wangshumin 4096 3月   8 11:41 ../
-rw-rw-r--  1 wangshumin wangshumin  260 3月   8 11:41 Dockerfile
wangshumin@machine1:~/sinatra$ cat  Dockerfile 
# This is a comment
FROM ubuntu
MAINTAINER Docker1 wangshumin <wangshumin@docker.com>
RUN apt-get  update
RUN apt-get  install -y net-tools
RUN apt-get  install -y iputils-ping
RUN apt-get install  -y nginx
RUN apt-get install  -y curl
EXPOSE 80
CMD /bin/bash
wangshumin@machine1:~/sinatra$ pwd
/home/wangshumin/sinatra

wangshumin@machine1:~/sinatra$ 

wangshumin@machine1:~/sinatra$ docker  build  -t="wangshumin_isodocker:v3" .
Sending build context to Docker daemon 2.048 kB
Step 1/9 : FROM ubuntu
 ---> 0458a4468cbc
Step 2/9 : MAINTAINER Docker1 wangshumin <wangshumin@docker.com>
 ---> Using cache
 ---> 3f38995f6df6
Step 3/9 : RUN apt-get  update
 ---> Running in 1fd462aefe28
Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Get:2 http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB]
Get:3 http://security.ubuntu.com/ubuntu xenial-security/universe Sources [73.2 kB]
Get:4 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [587 kB]
Get:5 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
Get:6 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
Get:7 http://archive.ubuntu.com/ubuntu xenial/universe Sources [9802 kB]
Get:8 http://security.ubuntu.com/ubuntu xenial-security/restricted amd64 Packages [12.7 kB]
Get:9 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [406 kB]
Get:10 http://security.ubuntu.com/ubuntu xenial-security/multiverse amd64 Packages [3486 B]
Get:11 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages [1558 kB]
Get:12 http://archive.ubuntu.com/ubuntu xenial/restricted amd64 Packages [14.1 kB]
Get:13 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages [9827 kB]


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Dockerfile 是一种文本格式的脚本,可以用来自动化构建 Docker 镜像创建 Docker 镜像的步骤如下: 1.编写 Dockerfile 文件,包括镜像的基础操作系统、安装软件、配置环境等; 2.在 Dockerfile 文件所在的目录执行 docker build 命令,构建 Docker 镜像; 3.使用 Docker run 命令启动 Docker 容器,可以使用该容器。 例如,创建一个基于 Ubuntu 18.04 的 Docker 镜像安装 nginx、PHP 和 MySQL,可以按照下面的步骤进行: 1.创建一个名为 Dockerfile 的文件,并在其添加以下内容: ``` FROM ubuntu:18.04 RUN apt-get update \ && apt-get install -y nginx php-fpm php-mysql mysql-server \ && rm -rf /var/lib/apt/lists/* COPY nginx.conf /etc/nginx/nginx.conf COPY php.ini /etc/php/7.2/fpm/php.ini CMD ["/usr/sbin/nginx", "-g", "daemon off;"] ``` 2.在 Dockerfile 文件所在的目录创建一个名为 nginx.conf 的文件,并添加以下内容: ``` user www-data; worker_processes auto; pid /run/nginx.pid; include /etc/nginx/modules-enabled/*.conf; events { worker_connections 768; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; error_log /var/log/nginx/error.log; server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; index index.php index.html index.htm; location / { try_files $uri $uri/ =404; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; } } } ``` 3.在 Dockerfile 文件所在的目录创建一个名为 php.ini 的文件,并添加以下内容: ``` date.timezone = Asia/Shanghai ``` 4.执行 docker build 命令,构建 Docker 镜像: ``` docker build -t myimage:latest . ``` 5.使用 Docker run 命令启动 Docker 容器: ``` docker run --name mycontainer -d myimage:latest ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值