首页 > 其他分享 >[Docker] Working With Prebuilt Docker Images

[Docker] Working With Prebuilt Docker Images

时间:2023-01-25 04:33:06浏览次数:46  
标签:httpd container Prebuilt nginx user Images Docker docker cloud

Pull httpd:latest image

Normally you want to attach the version httpd:2.4, because everytime you run the image, we with the same version is running. but here, we just use the latest

docker pull httpd

Run the httpd image

We can first check the image is there

docker images

Then we can run the our container

  • by give container a name just httpd, --name httpd
  • the port of server 8080 and insider container is 80: -p 8080:80
  • we want to run in detact mode: -d

docker run --name httpd -p 8080:80 -d httpd:latest

Now we can run the command

docker ps

to see that our container is running

CONTAINER ID   IMAGE          COMMAND              CREATED         STATUS         PORTS                                   NAMES
5fb3500a61b4   httpd:latest   "httpd-foreground"   3 seconds ago   Up 2 seconds   0.0.0.0:8080->80/tcp, :::8080->80/tcp   httpd

We can open the browser http://<public-ip-address>:8080 to see the site

Host a site on httpd

git clone https://github.com/linuxacademy/content-widget-factory-inc

so this is what inside the repo

[cloud_user@ip-10-0-1-22 ~]$ cd content-widget-factory-inc/
[cloud_user@ip-10-0-1-22 content-widget-factory-inc]$ ll
total 0
drwxrwxr-x. 3 cloud_user cloud_user 93 Jan 24 14:57 web
[cloud_user@ip-10-0-1-22 content-widget-factory-inc]$ cd web
[cloud_user@ip-10-0-1-22 web]$ ll
total 16
drwxrwxr-x. 2 cloud_user cloud_user   76 Jan 24 14:57 img
-rw-rw-r--. 1 cloud_user cloud_user 3059 Jan 24 14:57 index.html
-rw-rw-r--. 1 cloud_user cloud_user 2910 Jan 24 14:57 quote.html
-rw-rw-r--. 1 cloud_user cloud_user 2611 Jan 24 14:57 support.html
-rw-rw-r--. 1 cloud_user cloud_user 2645 Jan 24 14:57 widgets.html

First, we need to stop our container

docker stop httpd

But even we stop the container, it is still there, we can see the container by running

docker ps -a

[cloud_user@ip-10-0-1-22 content-widget-factory-inc]$ docker ps -a
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS                          PORTS     NAMES
5fb3500a61b4   httpd:latest   "httpd-foreground"       6 minutes ago    Exited (0) About a minute ago             httpd

To remove the container:

docker rm httpd

Mount our website into the container

  • We want to add a volume from the web folder of the project
  • to /usr/local/apache2/htdocs folder of conatiner
  • we want to attch ro as readonly, so docker can only read our files

docker run --name httpd -p 8080:80 -v $(pwd)/web:/usr/local/apache2/htdocs:ro -d httpd:latest

Now if you open the

Congras! you made http://<public-ip-address>:8080 in browser, you will be abel to see the site

Nginx

The good thing about container is that we can run multi of copies of web server at the same time. Let's try nginx

docker pull nginx:latest

Check the images

docker images

[cloud_user@ip-10-0-1-22 content-widget-factory-inc]$ docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
httpd        latest    6e794a483258   6 days ago    145MB
nginx        latest    a99a39d070bf   13 days ago   142MB

Then run the image

docker run --name nginx -p 8081:80 -d nginx:latest

This time we give port 8081

[cloud_user@ip-10-0-1-22 content-widget-factory-inc]$ docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS         PORTS                                   NAMES
6baffe67db0a   nginx:latest   "/docker-entrypoint.…"   3 seconds ago   Up 2 seconds   0.0.0.0:8081->80/tcp, :::8081->80/tcp   nginx
a187ff869044   httpd:latest   "httpd-foreground"       7 minutes ago   Up 7 minutes   0.0.0.0:8080->80/tcp, :::8080->80/tcp   httpd

Now if we open the site on http://<public-ip-address>:8081, we should be able to see the nginx welcome page!

So let's say we want to mount the website into nginx as well, we can repeat the process

# stop the container
docker stop nginx
# remove the container
docker rm nginx
# verify the container has been removed
docker ps -a
# mount the site into nginx
docker run --name nginx -p 8081:80 -v $(pwd)/web:/usr/share/nginx/html:ro -d nginx:latest

标签:httpd,container,Prebuilt,nginx,user,Images,Docker,docker,cloud
From: https://www.cnblogs.com/Answer1215/p/17066632.html

相关文章

  • docker磁盘
    docker容器跑久了,其产生的日志可能会占用比较多的空间[root@server1~]#df-h文件系统容量已用可用已用%挂载点devtmpfs475M......
  • Docker 容器添加自定义root ca
    比如如果我们基于了step-ca工具做为我们的ca机制,就会有不可信的问题,业务使用就特别不方便了,以下是一个参考配置实际上很简单就是使用update-ca-certificates更新信息......
  • docker容器日志清理
    最近发现linux(Centos7)虚拟机的空间不够了,想创建新的容器都失败。剩下不到100M。之前还有好几个G。然后每天不定期查看磁盘空间,发现不断被蚕食。今天比昨天就少了100M;然后下......
  • Docker 基础 - 1
    镜像获取镜像dockerpull查看镜像信息dockerimagesdockerinspect<imagesid>#获取镜像的详细信息搜寻镜像dockersearch删除镜像dockerrmi当一个镜像拥......
  • Docker安装PostgreSQL
    镜像地址:https://hub.docker.com/_/postgres1.拉取dockerpullpostgres2.创建dockerrun-d\-p5432:5432\--namepostgres\--restart=always......
  • Docker基础
    背景介绍Docker是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可抑制的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化。容器完全使用沙......
  • 远程连接Docker上的Mysql失败的解决方案
    之前VMWare虚拟机CentOS7使用DHCP,导致只要重启操作系统,网卡IP地址就改变。于是把网卡修改为手工设定IP地址,结果导致远程连接mysql出现如下错误,花了很多时间还没有解决,最终偶......
  • docker运行pm2程序
    DockerfileFROMnode:16.14.2RUNmkdir/data/apps-pv\&&[email protected]\&&npm-gipm2WORKDIR/data/appsCOPY..RUNpnpminstall\&&pnpm......
  • Docker 部署 SpringBoot 项目
    Dockerfilehouse.jar为jar包名称/data为存放路径FROMlpicanco/java11-alpineMAINTAINERchenglong<[email protected]>VOLUME/tmpRUNmkdir/dataEXPOS......
  • 在Docker上拉取一个现成的SystemC环境
    SystemC是在C++通过库拓展的一个可用于硬件电路设计的语言Docker是一种类似虚拟机的技术,但比虚拟机更方便,将一种环境所需的最小配置打包成一个image后,便可以方便地使用WS......