Docker is a tool that can package an application and its dependencies in an isolated container, which can be run on any server.
To easily use docker you have to download docker desktop.
After having followed the installation of docker you can in a terminal type the following command :
docker run -d -p 85:80 hello-world
In the docker desktop application a container should have appeared. If so, the installation worked.
To start, you will need to create a Dockerfile in a folder.
Once the Dockerfile is created, you can open it with your favorite editor (VSCode has some extensions for Dockers). There are several docker commands. We will look at the most important :
FROM allows you to specify the version and the image of the platform used by the docker (ex: ubuntu, centos, ...).
FROM {docker platform image}:{image version}
You can find all platform images here : platform image.
RUN instruction will execute any commands in a new layer on top of the current image and commit the results.
RUN {command}
or
RUN ["executable","param1", "param2"]
CMD allows to execute commands in the CMD of the container.
CMD ["executable","param1","param2"] (exec form, this is the preferred form)
or
CMD {command} {param1} {param2} (shell form)
EXPOSE instruction informs Docker that the container listens on the specified network ports at runtime.
EXPOSE {port}
For all other docker commands or for more details you can go to the docker doc.
Once your Dockerfile is finished, you just need to build the image. Run the command below in a command prompt open in the folder where your Dockerfile is located.
docker build --progress=plain -t {image name} .
Execute the command below in a command prompt to create a container running the desired image.
docker run -d -p {port}:{port} {image name}
- Luc ENEE
- Jess Leonatti