-
Notifications
You must be signed in to change notification settings - Fork 13
docker_quickstart
We present here the basic concepts and command/options to use GRANDLIB with Docker. We will detail the following:
- Some Docker concepts
- Retrieve a GRANDLIB Docker image
- Run a GRANDLIB container
- Re-use a container
- Enable graphics (to plot figure for example)
- Some clean commands
Docker is a solution of virtualization which has the particularity of being available on the 3 most used operating systems (Linux, Windows, MacOS). It makes Docker a simple solution for a large distribution of applications and software libraries.
Follow the installation procedure given by Docker documentation for different OS. To manage Docker as a non-root user
A Docker image is a read-only template used to build containers. Images are used to store and ship applications/libraries.
The docker image is defined by a name and a tag, so the 'complete name' of a Docker image is:
<name image>:<tag>
When <tag>
isn't specified the default value is
latest
A docker image can be also defined by an ID, and different 'complete name' of Docker image can have a same ID. See an example below with tag 'latest' and '0.1' for name 'jcolley/grandlib_eclipse'.
Given by
docker image ls
Example of response
REPOSITORY TAG IMAGE ID CREATED SIZE
jcolley/grandlib_eclipse 0.1 159bfcba4463 2 weeks ago 3.11GB
jcolley/grandlib_eclipse latest 159bfcba4463 2 weeks ago 3.11GB
grandlib_eclipse latest 539braba7865 2 weeks ago 3.45GB
A container is created from a Docker image and a set of parameters. A container is a runable instance of a Docker image. There can be multiple containers from the same image. A container has its own storage space in read/write mode, which allows it to evolve from the original image.
Containers aren't versioned and have 'simple' names. You can choose it at creation. Otherwise docker will create it for you with random words.
Given by
docker ps -a
used -a
for all, otherwise only the running container list is returned.
Example of response
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4e565c11b0e0 grandlib_eclipse "/bin/bash" 2 weeks ago Exited (0) 2 weeks ago eclipse2
854ff1525f20 grandlib_eclipse "/bin/bash" 2 weeks ago Exited (0) 2 weeks ago eclipse
1321207dae88 grandlib_dev_eclipse "/bin/bash" 2 weeks ago Exited (0) 2 weeks ago eclipse_gd
e6e93e602f5a sonarqube:lts "bin/run.sh bin/sona…" 4 months ago Up 4 seconds 0.0.0.0:9000->9000/tcp, :::9000->9000/tcp sonarqube
You can create and execute a container directly with docker run command
docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]
else you must use two commands
Find in GRANDLIB dockerhub different docker images:
- dev : contents GRANDLIB environment without sources
- release : contents GRANDLIB environment and an 'official' version of GRANDLIB ready to use
No configuration is required to retrieve an image. The command to retrieve an image is recalled for each tag, you can copy and paste it into your terminal, example:
docker pull grandlib/dev
A specific image for ARM64 is available with tag 2.0, for Apple M1 this image is 10 times faster than latest compiled for AMD64
By default , a GRANDLIB image starts with a shell bash, so just use the -it
option
jcolley:~$ docker run -it grandlib/dev
root@b9f1a9f0f700:/home# pwd
/home
root@b9f1a9f0f700:/home# exit
jcolley:~$
The default working directory is /home
. Another way to exit container is crtl+d
You can link a local directory in your containers with option -v (for volume). Example where:
- I created a file in local directory
jcolley$ touch newfile.txt
jcolley$ ls -l
total 12
drwxr-xr-x 16 jcolley informatique 4096 févr. 3 16:45 grand
-rw-r--r-- 1 jcolley informatique 0 févr. 21 15:53 newfile.txt
- create a container with the option
-v $PWD:/home/colley
to link your current directory to /home/colley in a container
jcolley$ docker run -it --rm -v $PWD:/home/colley grandlib/dev
root@98b14f2a68c9:/home# cd /home/colley
root@98b14f2a68c9:/home/colley# ls -l
total 12
drwxr-xr-x 16 20748 200 4096 Feb 3 15:45 grand
-rw-r--r-- 1 20748 200 0 Feb 21 14:53 newfile.txt
Note:
--rm
option deletes the container at exit, else you created different container for each docker run
command and add it to container list with status "Exited".
- create a file in the container in the directory linked
- exit docker
root@98b14f2a68c9:/home/colley# touch new_file_from_container.txt
root@98b14f2a68c9:/home/colley# ls -l
total 20
drwxr-xr-x 16 20748 200 4096 Feb 3 15:45 grand
-rw-r--r-- 1 root root 0 Feb 21 14:53 new_file_from_container.txt
-rw-r--r-- 1 20748 200 0 Feb 21 14:53 newfile.txt
root@98b14f2a68c9:/home/colley# exit
- check if the created file exists
jcolley$ ls -l
total 20
drwxr-xr-x 16 jcolley informatique 4096 févr. 3 16:45 grand
-rw-r--r-- 1 root root 0 févr. 21 15:53 new_file_from_container.txt
-rw-r--r-- 1 jcolley informatique 0 févr. 21 15:53 newfile.txt
Note:
The file created in the container has root owner ! if you want to concern your username in docker container use this option with docker run:
--user "$(id -u):$(id -g)"
Instead of creating and deleting (with --rm option) a container each time, you can re-use the instance of container with the command docker start
- Create a container with the option
--name dev_grand
instead--rm
- Create a file in the container storage space (e.g. /home)
- Exit the container
jcolley$ docker run -it --name dev_grand -v $PWD:/home/colley grandlib/dev
root@34f8924399bd:/home# touch container_dev_grand.txt
root@34f8924399bd:/home# ls -l
total 4
drwxr-xr-x 7 20748 200 4096 Feb 21 14:53 colley
-rw-r--r-- 1 root root 0 Feb 21 15:21 container_dev_grand.txt
root@34f8924399bd:/home# exit
exit
- Check if the container with name dev_grand exists
jcolley$ docker ps -a | grep dev_grand
CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES
34f8924399bd grandlib/dev "/bin/bash" 51 seconds ago Exited (0) 11 seconds ago dev_grand
- Restart it with the command
docker start
jcolley$ docker start -ia dev_grand
root@34f8924399bd:/home# ls -l
total 4
drwxr-xr-x 7 20748 200 4096 Feb 21 14:53 colley
-rw-r--r-- 1 root root 0 Feb 21 15:21 container_dev_grand.txt
root@34f8924399bd:/home# exit
Your file is still there!
In the same way you can install an application as your favorite IDE and thus customize your container to your needs. Example add IDE greany to your container:
apt install -y geany
but before your need to enable graphics with docker
To enable graphics correctly you can review the following tutorials:
- Graphic configuration for Docker under Linux
- Graphic configuration for Docker under Windows 10
- Graphic configuration for Docker under MacOS
docker run -it --name grand4dev -p 8888:8888 -v $PWD:/home --net=host -e="DISPLAY" -v="$HOME/.Xauthority:/root/.Xauthority:rw" --user "$(id -u):$(id -g)" grandlib/dev
Start to clean containers and after docker images else deletion request is rejected because image is linked with existing container.
docker rm <CONTAINER ID>
docker rmi <IMAGE ID>
$ git clone https://github.com/grand-mother/grand.git
$ docker run -it --rm -v $PWD:/home grandlib/dev
root@58788b7dc04e:/home# ls grand
bin COPYING.LESSER docs env examples grand lib LICENSE log.txt quality
README.rst src tests wheel
root@dc6f5b78ef35:/home# cd grand
root@dc6f5b78ef35:/home/grand# source env/setup.sh
....