Getting started with docker

Updated on: 01/10/2025 Danny
Version Française

Docker is a platform for running applications in containers.

You can run your applications on any system.

It facilitates the deployment, scalability and management of services.

Docker has become an essential tool for developers and DevOps teams.

intro alt 00001
demarrer-avec-docker-guide.png

If you don't have time to read this entire guide,
download it now


How to do it

In this simple tutorial a summary of some essential commands.

  • Facility
  • Orders
  • Images
  • Containers
  • Dockerfile
  • Example Hello

Documentation

Official website
https://www.docker.com/

Installation Procedures
https://docs.docker.com/install/linux/docker-ce/ubuntu/

Searching for images on docker hub
https://hub.docker.com/


Installation


# Installation
sudo apt-get --yes install docker.io

# Uninstalling old versions
sudo apt-get remove docker docker-engine docker.io containerd runc --yes

# Testing the installation
sudo docker run hello-world

# Rights management
sudo usermod -aG docker ${USER}

# Restart to take rights into account
reboot

Orders


# Indicates the docker version
sudo docker version

# Restarting the docker service
sudo service docker restart

# List of images
docker images
docker image ls

# List of containers
docker ps -a
docker container ls

# Delete all images
docker rmi $(docker images -q)

# Clear all containers
docker rm $(docker ps -a -q)


Images


# Search for an image
sudo docker search nginx

# Repatriate an image
docker pull nginx

# Repatriates an image to a specific version
docker pull nginx:1.17.9
docker pull nginx:latest
docker pull node:12.16.1

# Delete an image with image_id
docker rmi image_id

# Delete an image with image_id in forced mode
docker rmi -f image_id

# Rename an image containing image_id 0a
docker tag 0a new-name:tag-name

Containers

Options

  • -d : daemon
  • -p : publish
# Run a container named frontend from an nginx image
sudo docker pull nginx:1.17.9
sudo docker run --name frontend -d -p 80:80 nginx:1.17.9

# Stops a container named frontend
docker stop frontend

# Deletes a container named frontend
docker rm frontend

# Restart a container
docker restart frontend

# Deletes a container named frontend in force mode
docker rm frontend -f         

# Renames an old-name container to a new-name container
docker rename old-name new-name

# View logs
docker logs frontend

# Enter the container in execution mode
docker exec -it frontend /bin/bash

Dockerfile


.dockerignore
.git
*Dockerfile*
*docker-compose*
node_modules
Dockerfile
FROM nginx:1.17.9
LABEL author="www.ganatan@com"
COPY /dist/angular-starter/browser /usr/share/nginx/html
# Creating an image from the default dockerfile
# Name image-name , Tag 1.0.0
docker build -t nom-image:1.0.0 .

# Create an image from the dockerfile named Dockerfile-specific
docker build -t nom-image:1.0.0 -f Dockerfile-specific .

# Running the container on port 5000
docker run --rm  --name nom-container -d -p 5000:80 nom-image:1.0.0

# Enter the container in execution mode
docker exec -it nom-container /bin/bash

Create a Hello image


hello/Dockerfile
FROM busybox:latest
ADD index.html /www/index.html
EXPOSE 4000
CMD httpd -p 4000 -h /www; tail -f /dev/null
hello/index.html
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, user-scalable=no">
  <title>titre de notre page</title>
</head>

<body>
  Page Hello
</body>

</html>
# position yourself in the hello directory containing the Dockerfile file
# Create an image with a random name from the busybox image
docker build .

# Create a hello:latest image from the busybox image
docker build -t helloimage:1.0.0 .

# Execute the container but port 4000 not visible
docker run --rm -d helloimage:1.0.0

# Execute the container but port 5000 visible in non-daemon mode
docker run --rm -p 5000:4000 helloimage:1.0.0

# Execute the container but port 5000 visible in daemon mode
docker run --rm -d -p 5000:4000 helloimage:1.0.0

# Execute the container with the name hellocontainer
docker run --rm  --name hellocontainer -d -p 5000:4000 helloimage:1.0.0

Docker registry

Create a Docker image on Docker Hub.
Make it publicly accessible.

# Connection au docker Hub
docker login -u "my_name" -p "my_password" docker.io

# Tag our image
docker tag helloimage:1.0.0 my_name/angular-example-starter:1.0.0

# Push the image to docker Hub
docker push my_name/angular-example-starter:1.0.0

# Get the image to your workstation from Docker Hub
docker pull my_name/angular-example-starter:1.0.0

# Run the image in a container
docker run --rm --name hellocontainer -d -p 80:4000 my_name/angular-example-starter:1.0.0

Volumes


# Creating a volume
docker volume create volume-test

# List of volumes
docker volume ls

How to create a From scratch application?

Create your ganatan account

Download your complete guides for free

Démarrez avec angular CLI Démarrez avec angular CLI

Gérez le routing Gérez le routing

Appliquez le Lazy loading Appliquez le Lazy loading

Intégrez Bootstrap Intégrez Bootstrap


Utilisez Python avec Angular Utilisez Python avec Angular

Utilisez Django avec Angular Utilisez Django avec Angular

Utilisez Flask avec Angular Utilisez Flask avec Angular

Ganatan site Web avec Angular