Docker Light-weight virtualization - for class 2
admin
2023-03-07 21:36:54
0

Docker class 2 : run the docker image and introduce the docker volume and web server


(1)
we will introduce how to use docker to run in backdround !


docker run -it -d chusiang/takojs1607 /bin/bash -c "while true; do echo 'hi'; sleep 1; done"

-d means daemon , run in the background! you can use docker ps -a see the docker process which run in the background !
-c means "while true; do echo 'hi'; sleep 1; done" is string
for example , the container ID is f0e
you can use this command to see the logs.

docker logs f0e

(2)
you can use this command to give container name which you run


docker run -it -d --name test1 chusiang/takojs1607

--name means the container name

(3)
the data haven't seen when you closed the docker if you close directly
you can use docker voulme to save the data in docker!
on the basis of the first class , we create the environment to show that !
First , you need to change the user for root !

cd /
mkdir /mydata
cd mydata/
echo "hello world" > hello.txt
docker run -it -v /mydata:/data chusiang/takojs1607 /bin/bash
-v means volume
/mydata is local host
/data is docker folder

(4)
if you want to open a new terminal in docker containers which is the same container ID , you can use this command

docker exec -it CONTAINER ID bash

(5)
if you want to remove docker containers automatic after finished the docker container , you can add --rm when you start the docker container!

docker run -it --name test1 --rm chusiang/takojs1607 /bin/bash

(6)
if you want to switch terminal to host, you can tap the control +P +Q in your keyboard. if you want to use docker container , just attach it !

(7)
docker is the Light-weight virtualization , Many packages are not installed in it ! For example : ifconfig ,ping etc.
if your docker is ubuntu , you can use apt-get update , and apt-get install net-tools.
But !! Most important is it will disappear if you restart the docker .
so , you can create a new docker images with the package installed
For example , the container ID is ccea9d4e9655

docker commit cce ubuntu:mv1

then , you can start the docker new images with ifconfig tools!
if you want to remove the docker images , you can use this command

docker image rm IMAGE ID


How to use Web server in docker !?
we want to create the web page in the host virtual machine and map to the docker for starting the web server
For the first , we need to pull the docker images with httpd from docker hub

docker pull httpd

and the document root is /usr/local/apache2/htdocs/

Now, we will create the webpage.

cd /mydata/
echo "this is a index webpage" > index.html
echo "hi" >hi.htm

Start the docker container with apache

docker run -itd --name mywebserver -p 8080:80 -v /mydata:/usr/local/apache/htdocs/ httpd

-p means port
8080 is local port
80 is docker port

you can use curl 127.0.0.1:8080 for test !!!
For important, you can edit the webpage in local !
After edited , the docker web server will update!

相关内容

热门资讯

菲尔兹奖得主王虹4岁不慎烫伤,... 中国数学家王虹、邓煜获得菲尔兹奖,这是中国籍数学家首次获得这一奖项。王虹1991年出生在广西桂林平乐...
美媒:特朗普下令暂停空袭伊朗 美国“Axios”新闻网7月25日援引知情人士报道,特朗普24日指示美军不得对伊朗发动新的打击,打破...
法国野火“创历史纪录”:政坛吵... 综合法媒BFM新闻台、《费加罗报》报道,当地时间7月25日中午,内政部长努内兹(Laurent Nu...
51.79亿,携程真的疼了吗? 2026年7月25日,市场监管总局对携程反垄断案作出行政处罚:罚没款合计51.79亿元。但这个数字被...
一艘越南籍渔船在南沙遇险,29... 新华社三沙7月25日电(记者赵颖全)记者从三沙海上搜救中心获悉,25日傍晚,一艘越南籍渔船在南沙永暑...
成都如何耕好新型工业化“试验田... 7月24日,APEC数字周城市侧配套活动——制造强国建设专家研讨暨新型工业化推进交流会举行,院士专家...
活力中国调研行丨检测设备“长腿... 从排放控制的细分龙头到智能装备的新入局者,凯龙高科的转型路径,为观察传统制造业如何切入新赛道提供了一...
原创 别... 别被顶级奖项光环忽悠透了!拿菲尔兹奖的王虹,道出基础科研最现实的人间落差 开篇:大众脑补的名利双收,...
温州划龙桥惠耳——如何应对老年... 年近古稀的老人,近来时常出现耳鸣。周日,孩子们来了,跟她说话,声音小了她听不清,声音大了她嫌吵得慌,...
民调:包括共和党人在内,美国人... 据美国有线电视新闻网(CNN)当地时间24日报道,多项最新民调结果显示,包括许多共和党人在内,美国民...