Docker
docker ps
List of running containers
docker ps -a
List of running containers and also exited containers
docker rm CONTAINER_ID
Remove container
docker run hello-world
We are telling docker that we want to container with image called hello-world
. Docker tries to find it locally. As it wasnt successfull, it was downloaded from Docker Hub (public images repository). It shows as message Hello from Docker
, that is message from the container. Script finished and container turned off.
docker run -it --name mujDebian debian bash
We will create our own container called mujDebian
and start process bash
.
We are now inside container in Debian
. We will install simple static server, then we will create config file and simple html page. Finally we exit
from container.
docker diff mujDebian
This will show differences which we made in container - installation of webserver and simple html and config file
Lets create new image from this our container.
docker commit mujDebian michalmachovic:mujWebImage
docker images
will show us all docker images
docker run -d -p 9080:80 --name mujWeb michalmachovic:mujWebImage lighttpd -D -f lighttpd.conf
Now we will run new container with this image.
-d means that we will run it in background
-p means that we want to connect to service which container offers from outside. In our case this will be simple webserver, which we created inside container running on port 80
, to the outside Docker will serve this on port 9080
.
curl 127.0.0.1:9080/index.html
should show our page
Our container has disadvantage, it is static. What happen if we will want to start from another version of Debian ? Or another version of webserver ? We need to do container again manually. We can automate this.
On your local computer, create new directory and create the same index.html
and lighttpd.conf
files. Also in this folder create Dockerfile
with following content:
FROM - from which container we want to start
RUN - will be executed after container start, it will create whole new layer, its good to put all installations into one RUN
EXPOSE - saying there is something running inside container on port 80
ADD - add files from local directory to container
CMD - this will happen after start of new finished container, in our case it will run lighttpd webserver (so we dont need to type it manually)
docker build -t michalmachovic:dalsiWeb .
build our new container, check it exists with docker images
.
docker run -P --name dalsiWebKontejner2 michalmachovic:dalsiWeb
lets run our new container with -P
parameter, we specified inside port with EXPOSE
, so this will assign some free port on host system.
You should something like 2019-03-13 10:42:01: (log.c.217) server started
.
Now if you do docker ps
in new terminal window, you should see something like:
You can see 0.0.0.0:32768->80
, that means it will run on port 32768
, you can test this with curl 127.0.0.1:32768/index.html
.
http://www.cloudsvet.cz/?p=198
https://www.zdrojak.cz/clanky/proc-pouzivat-docker