What is docker?

Docker in general

Basically docker help us to create development environment which can be shared along team of developers regardless from operating system they use.

Bassic commands to work in docker

First of all if you run docker on Windows machine you wull need to use “Windows Power Shell” command terminal. If you use any other terminal you most likly will run in to problems. That said we are ready to start our jurnay with docker.

First donload and install docker on your machine.

See instalation manual page from docker docs here. As you can notice docker developed a desktop app for Mac and Windows users. For linux user you can run docker directly from terminal. Read installation page at docker docs for more informations.

Run first docker commands

For this tutorial we will use only docker termianl so it workss for all windows, mac and linux users. Go to termianl (Power Shell on Windows) and lest download a lamp container by Matt Rayner > github page (for desc and instalation instruction).

To download docker image use docker pull as in example below:

docker pull mattrayner/lamp

* instalation make take few min so be patient

Once the image is downloaded you can list all available images using this comand:

// docker image ls
docker images

Let see if there are any continers running at the moment.

// docker container ls
docker ps
* we shoud not see any containers run at the moment since we did not start any yet (unless you did) then you can use a command docker kill containeridhere to kill unused containers.

Your docker image is not runniing yet so lets go and run it now. We now need to run the container with command as fallow:

// on linux
docker run -p "80:80" -v ${PWD}/app:/app mattrayner/lamp:latest-1804

// on windows 
docker run -p "80:80" -v C:\path\to\my\app:/app mattrayner/lamp:latest-1804

Your terminal will now stop being interactive as i will run service in background this is normal. You need now to open a new terminal widnow to work with docker container.

Let see if there are any continers running at the moment.

// docker container ls
docker ps

Login in to runing container

To log in to runing container you need to use docker exec comamnd falled by -ti then container id and program:

docker exec -ti 4a94aef49e3a /bin/bash

https://www.saashub.com/compare-docker-vs-xampp

Setting up docker with node.js express app

After installing docker you will get propped with tutorial. If not you can restart your docker software to it default settings and access it this way. After installation or reset you will get link to page that will introduce you with building env for an TODO APP.
The APP is actually provided in docker documentation to download and it is actually very smal but functional software. http://localhost/tutorial/our-application/ which is also available on https://docs.docker.com/get-started/

You need to fallow the instruction in the above tutorial link from docker documentation.

Download app src zip code

Unzip app in the folder of your choice

cd the app folder and create Dockerfile. Copy and paste default configuration the run in the same directory run:

docker build -t getting-started .

docker run -dp 3000:3000 getting-started

After making changes to our files we will need to create our container again. But without stoping the old container we will not be able to access the app because port 3000 will be in use. So we need to stop and probably remove old container.

This will list running containers and it id
docker ps

Stop command will stop running container.
docker stop 189a37a68763

Remove will delete container. *Container need to be stopped before you can remove it!
docker rm 189a37a68763

We could also combine those two commands using (this would stop and remove container as we did it before):
docker rm -f 189a37a68763

You can also stop and remove containers from the docker app.

Build volume
docker volume create todo-db

docker rm -f <id>

Run app and load persisted volume data.
docker run -dp 3000:3000 -v todo-db:/etc/todos getting-started

Check where the volume data are stored
docker volume inspect

Documentation tutorial is written so well that everyone can fallow up and for that reason there is no point to rewrite everything what is out there to this blogpost. So please go through documentation tutorial to get more information on how Docker works, how it persist data in image and containers, and how to mount data for instance change without rebuilding the container over and over to be able to notice code edits. This and many more is very well described.

http://localhost/tutorial/using-bind-mounts/

Other useful commands self-explanatory
docker logs -f <container-id>

0
Would love your thoughts, please comment.x
()
x