Docker is a softwar that allows you to work in ‘containers’ with different environments from that of your machine. For example different operating system or different versions of one operating system. Before being able to use Docker:

  • You need to install Docker following the instructions adequate to your operative system.
  • Test your instalation with (in linux you might need to run first newgrp docker, see the linux-postinstall):
    docker run hello-world
  • Make an account on the website

Compiling and running a program in a different environment

If you are going to work in a given environment for a project, you can create a directory with the program that you want to test, ‘hello.cpp’, and the file ‘Dokerfile’, with the needed comands. This is an example ‘Dockerfile’:

FROM ubuntu:16.04

RUN apt-get update && apt-get install -y g++

COPY . /usr/src/

WORKDIR /usr/src/

RUN g++ -o hello hello.cpp

CMD ["./hello"]

Then you need to build the image that will run the program, by typing in the same folder as the ‘Dockerfile’:

$ docker build -t my-gcc-app .

And run the Docker image

$ docker run -it --rm --name my-running-app my-gcc-app 

Comandos docker

IMAGE = name of the image; TAG = tag name

docker build --tag TAG . builds a local image in current directory (with Dockerfile)
docker images lists local images
docker image rm IMAGE removes image
docker run IMAGE:TAG runs image with IMAGE:TAG name
docker ps lists running processes
docker ps -a lists all processes
docker start/stop IMAGE starts/stops image
docker system prune -a removes any dangling and stopped resources