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!

相关内容

热门资讯

重磅消息“中至万年麻将.有挂吗... 您好:中至万年麻将这款游戏可以开挂,确实是有挂的,需要了解加客服微信【9752949】很多玩家在这款...
终于了解“八闽福建麻将.究竟有... 有 亲,根据资深记者爆料八闽福建麻将是可以开挂的,确实有挂(咨询软件无需...
玩家分享攻略“新九方炸金花.有... 有 亲,根据资深记者爆料新九方炸金花是可以开挂的,确实有挂(咨询软件无需...
终于明白“闽乐茶楼.有没有挂?... 有 亲,根据资深记者爆料闽乐茶楼是可以开挂的,确实有挂(咨询软件无需打开...
终于了解“福麻圈.到底是不是挂... 家人们!今天小编来为大家解答福麻圈透视挂怎么安装这个问题咨询软件客服徽4282891的挂在哪里买很多...
【今日要闻】“卡贝大厅.有挂吗... 您好:卡贝大厅这款游戏可以开挂,确实是有挂的,需要了解加客服微信【4282891】很多玩家在这款游戏...
重磅消息“新大圣牛牛.辅助开挂... 有 亲,根据资深记者爆料新大圣牛牛是可以开挂的,确实有挂(咨询软件无需打...
【第一资讯】“星星武汉麻将.是... 您好:星星武汉麻将这款游戏可以开挂,确实是有挂的,需要了解加客服微信【4282891】很多玩家在这款...
重磅消息“约战丹东麻将.辅助器... 家人们!今天小编来为大家解答约战丹东麻将透视挂怎么安装这个问题咨询软件客服徽9752949的挂在哪里...
玩家分享攻略“丫丫古诗.可以开... 网上科普关于“丫丫古诗有没有挂”话题很是火热,小编也是针对丫丫古诗作*弊开挂的方法以及开挂对应的知识...