Skip to content

3. Usage

Filip Zorić edited this page May 18, 2024 · 1 revision

How to build Dockerfile?

Enter corresponding directory and run following command to build docker image:

docker build -t <image_name>:<tag_name> <dockerfile_path> 

For concrete example (ros-kinetic with gazebo) run following:

docker build -t ros_gazebo_img:melodic_11 .

How to create container out of the Dockerfile?

In order to create container from Dockerfile run following commmand:

docker run -it --network host --privileged -v /dev:/dev --name <container_name> <img_name>:<tag_name> 

Run docker container with GUI support

docker run -it --network host --gpus all --privileged -e DISPLAY=$DISPLAY -v /dev:/dev -v /tmp/.X11-unix:/tmp/.X11-unix \
       --name <container_name> <img_name>:<tag_name> 

Also, before using param --gpus make sure you've installed nvidia-container-toolkit as mentioned before.

Make sure you have latest drivers for your GPU.

How to start existing docker container after stopping it?

docker start -i <container_name> 

How to open running container in new bash?

docker exec -it <container_name> bash 

How to kill, stop, remove container?

Kill container:

docker kill  <container_name> 

Stop container:

docker  stop <container_name> 

Remove container:

docker rm <container_name> 

Attach existing detached cotainer:

docker attach <container_name> 

Clean dangling images and stopped containers (bear in mind that this deletes every container that's not currently running, not recommended):

docker system prune 

Example of build args

There's example of using build-args for installing IDE in container in following Dockerfile

docker build --build-arg <arg_name>=<arg_value> -t <image_name>:<image_tag> .

Commit docker container to docker image

You can commit current state of docker image as follows:

docker commit --author filip.zoric@fer.hr --pause --message "[fer-auth] integration" mmuav_audio_cont auth_fer_uav_img:latest

Such image you can then compress to tar.gz or push to docker registry.

Save docker image

You can save docker image with docker save command and compress it to gzip as follows:

docker save <img_name>:<tag> | gzip > <archive_name>.tar.gz

Clone this wiki locally