[Docker] Working With Prebuilt Docker Images
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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2022-01-25 [AWS] AWS Inspector vs AWS Trust Advisor
2022-01-25 [JS Pattern] Container / Presentational Pattern
2019-01-25 [Node.js] Show More Lines in a Node.js Error Stack Trace
2019-01-25 [TypeScript] Deeply mark all the properties of a type as read-only in TypeScript
2019-01-25 [Angular] Angular Attribute Decorator - When to use it?
2017-01-25 [RxJS] Add debug method to Observable in TypeScript
2017-01-25 [Angular] NgRx/effect, why to use it?