Difference between revisions of "Docker tutorial"

From rbachwiki
Jump to navigation Jump to search
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
==Installing Docker on Ubuntu ===
==Installing Docker on Ubuntu ===
curl -fsSL https://get.docker.com -o get-docker.sh
=== Uninstall old version first===
sudo sh get-docker.sh


== Docker Commands ==
  sudo apt remove $(dpkg --get-selections docker.io docker-compose docker-compose-v2 docker-doc docker-buildx podman-docker containerd runc | cut -f1)
  docker run application
'''apt might report that you have none of these packages installed.'''
Run application, if it does not exist, it will pull it down


docker ps
'''Images, containers, volumes, and networks stored in /var/lib/docker/ aren't automatically removed when you uninstall Docker. If you want to start with a clean installation, and prefer to clean up any existing data, read the uninstall Docker Engine section [https://docs.docker.com/engine/install/ubuntu/#uninstall-docker-engine].'''
list all running containers


docker ps -a
===Install using the apt repository===
see all running container
'''Before you install Docker Engine for the first time on a new host machine, you need to set up the Docker apt repository. Afterward, you can install and update Docker from the repository.'''
<pre>
# Add Docker's official GPG key:
sudo apt update
sudo apt install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc


docker stop
# Add the repository to Apt sources:
stop a container
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF


docker rm
sudo apt update
remove a container
</pre>


  docker images
===Install the Docker packages.===
list images locally
  sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin


  docker rmi nginx
===After installation, verify that Docker is running:===
will delete the image permanently
  sudo systemctl status docker


  docker inspect container_name
'''If Docker is not running, start it manually:'''
get more info on a container
  sudo systemctl start docker


===Verify that the installation is successful by running the hello-world image:===


docker logs container_name
sudo docker run hello-world
show logs of a container




==Persistent Data==
''' if you create a mysql docker container and store everything in the container, when you delete the container everything will be lost'''
''''To store the msql files outside the container , you would have to map the storage to an outside directory'''
docker run -v /opt/datadir:/var/lib/mysql mysql
this will mount the /opt/datadir to the internal /var/lib/mysql folder




docker pull nginx
will pull the nginx image down but not run it
docker exec nameofdockerinstance cat/etc/hosts
run a command withing the docker instance
run redis:4.0
run a specific version of a software
docker run -it ubuntu
run an app and attach to it terminal in an interactive mode
==Port Mapping==
''' Every docker container get's a local ip assigned (internal)'''
'''you have top map the internal port to the external ip and port'''
docker run -p 80:5000 webapp
80 is the external port and 5000 is the internal port




==[[Docker]]==
==[[Docker]]==

Latest revision as of 17:40, 5 November 2026

Installing Docker on Ubuntu =

Uninstall old version first

sudo apt remove $(dpkg --get-selections docker.io docker-compose docker-compose-v2 docker-doc docker-buildx podman-docker containerd runc | cut -f1)

apt might report that you have none of these packages installed.

Images, containers, volumes, and networks stored in /var/lib/docker/ aren't automatically removed when you uninstall Docker. If you want to start with a clean installation, and prefer to clean up any existing data, read the uninstall Docker Engine section [1].

Install using the apt repository

Before you install Docker Engine for the first time on a new host machine, you need to set up the Docker apt repository. Afterward, you can install and update Docker from the repository.

# Add Docker's official GPG key:
sudo apt update
sudo apt install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF

sudo apt update

Install the Docker packages.

sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

After installation, verify that Docker is running:

sudo systemctl status docker

If Docker is not running, start it manually:

sudo systemctl start docker

Verify that the installation is successful by running the hello-world image:

sudo docker run hello-world




Docker