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!

相关内容

热门资讯

黄土塬藏“算力密码”!中国电信... 在陇东黄土塬上,数字浪潮奔涌不息。作为国家 “东数西算” 工程的核心承载地,中国电信庆阳智算产业园正...
科沃斯加入清洁电器行业反虚假测... 【CNMO科技消息】5月8日,科沃斯官方微博宣布,科沃斯加入由中国家用电器协会指导、中国家电网发起成...
东华科技获得发明专利授权:“一... 证券之星消息,根据天眼查APP数据显示东华科技(002140)新获得一项发明专利授权,专利名为“一种...
头部企业扎堆超百场无人机赛事,... 文/陈聆听 2026 年 5 月 4 日,山东诸城,山东天鸟航空负责人丁总与当地多位中小学校长会面,...
重磅签约!华为、中国银联战略合... 快科技5月8日消息,华为和中国银联在深圳正式签约,进一步深化双方的战略合作,还一起发布了自主创新和人...
胡锡进:日本已成中国“头号潜在... 日本高市早苗政府代表了日本政治思维,特别是对华策略最阴暗的一面,这个女人绝对是“政治女巫”级别的。中...
“190元榴莲遭仅退款”商家:... 近日,河南濮阳一冷冻榴莲果肉商家“程大叔”反映,自己遭遇一名买家恶意“仅退款”。为讨回公道,4月28...
新价格项目落地,让医疗真创新更... “让瘫痪的人能动、心衰末期的人能活、万里之外能手术”,这些看似奇迹的变化,背后藏着一个关键支撑—近三...
苹果宣布在印度扩大三项环保举措... 【CNMO科技消息】近日,苹果宣布扩大在印度的环保举措,共推出三个相关项目,覆盖清洁能源、塑料污染治...
华为在数字中国建设峰会:只有根... 作者:王聪彬 “根技术、落地”是华为在第九届数字中国建设峰会想要传递出的两个关键字。 “根技术”顾名...