Docker

Docker knowledge goes here

Installation

Installation

Installing Docker on Fedora 31

Uninstall old versions
Older versions of Docker were called docker or docker-engine. If these are installed, uninstall them, along with associated dependencies.

$ sudo dnf remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine

SET UP THE REPOSITORY
Install the dnf-plugins-core package which provides the commands to manage your DNF repositories from the command line.

$ sudo dnf -y install dnf-plugins-core

Use the following command to set up the stable repository.

$ sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo


INSTALL DOCKER ENGINE - COMMUNITY
Install the latest version of Docker Engine - Community and containerd, or go to the next step to install a specific version:

$ sudo dnf install docker-ce docker-ce-cli containerd.io

If prompted to accept the GPG key, verify that the fingerprint matches 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35, and if so, accept it.

Cgroups Exception For Fedora 31, you’ll have to enable the backwards compatibility for Cgroups.

$ sudo grubby --update-kernel=ALL --args="systemd.unified_cgroup_hierarchy=0"

Start Docker

$ sudo systemctl start docker

Enable Docker for startup

$ sudo systemctl enable docker

RESTART Linux

Verify that Docker Engine - Community is installed correctly by running the hello-world image.

$ sudo docker run hello-world

Source: https://docs.docker.com/install/linux/docker-ce/fedora/

Cheat Sheet

docker pull <image> -> Download image on its latest version from docker hub
docker images -> Lists images
docker run <image> -> Starts container attached. If local image not found, it downloads it
docker run -d <image> -> Starts container detached
docker run <image>:<version> -> Starts container in specific version
docker run -p<accessible_port>:<internal_port> -> Binds a port from the service within docker (internal_port)) to an accessible_port
docker ps -> Shows running containers
docker ps -a -> Shows running and stopped conatiners containers
docker stop <ID> -> Stop container ID of container (get it from docker ps)
docker start <ID> -> Start container previously stopped. ID of container (get it from docker ps -a)

 

Docker failing to start

Check the error running it in debug mode:

dockerd --debug

In case the error is something like:
failed to start daemon: Error initializing network controller: Error creating default "bridge" network: Failed to program NAT chain: ZONE_CONFLICT: 'docker0' already bound to a zone

Run:

sudo firewall-cmd --permanent --zone=trusted --remove-interface=docker0
sudo firewall-cmd --permanent --zone=FedoraWorkstation --remove-masquerade
sudo firewall-cmd --reload
sudo systemctl restart docker

Training notes

https://www.linkedin.com/learning/paths/developing-and-delivering-software-with-docker?u=76815018

Run docker as NON-ROOT:

sudo groupadd docker
sudo usermod -aG docker $USER

Logout and login. If still fails, run:

sudo chmod 666 /var/run/docker.sock

Run hello world image

docker run hello-world

List images

docker images

Run bash from an ubuntu latest image container. Note: This won't delete the container once you exit. It will stop the container if you exit.

docker run -it ubuntu:latest bash

:latest is optional. If not informed, docker will always get latest

docker run -it ubuntu bash

--name <name> allows you to provide a name. If not informed, docker will give a name to it

docker run --name <name_for_the_container> -it ubuntu bash

Run bash from an ubuntu latest image container. Note: This WILL delete the container once you exit. It will stop the container if you exit.

docker run --rm -it ubuntu bash

Other example:

docker run --rm -it ubuntu bash -c "sleep 3; echo all done"

Run detached container. Note: It will make it run in the background.

docker run -d -it ubuntu bash

To attach to the container

docker attach <container_name or container_ID>

From within a container, use CTRL-p + CTRL-q to detach from it. You can reatach using the command above

List docker running containers

docker ps

List all docker (running or not) containers

docker ps -a

Show last created container

docker ps -l

Create an image from a container

docker commit <container_name or container_ID> <new_image_name>

Run another shell from a running container

docker exec -it <container_name or container_ID> bash

See logs of a container that somehow failed

docker logs <container_name or container_ID>

Stop a running container

docker kill <container_name or container_ID>

Remove a stopped container

docker rm <container_name or container_ID>

Restart a container automatically if it dies

docker run -d -p 5000:5000 --restart=always --name registry registry:2

Open port and use external and internal to docker as the same number

docker run -ti -p 45678:45678 ubuntu bash

To allow docker manage the external port number, do:

docker run -ti -p 45678 --name test ubuntu:latest bash

To find what ports are open, run

docker port <container_name or container_ID>

List Docker Networks

docker network ls

Create new Docker network

docker network create <network_name>

Create a container in a network

docker run --rm -ti --net <network_name> --name <container_name> ubuntu:latest bash

Delete docker images
List images first

docker images

To delete, use Image ID

docker rmi <image_name>

Persist data into a volume
Create a folder at the server

mkdir <path_to_server_folder>

Run container

docker run -ti -v /<path_to_a_local_folder>:/<path_to_container_folder> ubuntu bash

Example

docker run -ti -v /opt/share:/shared-folder ubuntu bash

Share data between containers. Note: this data is not persisted when the containers are removed
Create the container holding the volume

docker run -ti -v /shared-data --name first_container ubuntu bash

Create the container(s) that will see this volume

docker run -ti --volumes-from first_container ubuntu bash

Search docker images

docker search <keyword>

Example

docker search ubuntu

Also visit https://hub.docker.com

 

Aliases to run commands in docker

The following examples will allow the run the corresponding commands within docker of a file outside of docker, i.e. a local file:

alias docker-php='docker run --rm -itv $(pwd):/app -w /app php php'
alias docker-python='docker run --rm -itv $(pwd):/app -w /app python python'

Usage:

docker-php myfile.php
docker-python myfile.py

Installing Oracle 19c in a docker container

Installing Oracle 19c in a docker container

Reference: https://mkc110891.medium.com/oracle-19c-on-ubuntu-18-04-docker-6898cd2916f9

1 - Clone Oracle Dockerfile Images
git clone https://github.com/oracle/docker-images

2 - Download Oracle 19c zip from Oracle website

You can download the zip from https://www.oracle.com/database/technologies/oracle-database-software-downloads.html#19c
Download Linux x 86–64 from 19.3 section.

Copy zip file in docker-images/OracleDatabase/SingleInstance/dockerfiles/19.3.0/.

cp <path-of-download-directory>/LINUX.X64_193000_db_home.zip docker-images/OracleDatabase/SingleInstance/dockerfiles/19.3.0/

3 - Run Docker Image builder
cd docker-images/OracleDatabase/SingleInstance/dockerfiles
./buildContainerImage.sh -v 19.3.0 -e

Check images and confirm oracle image is listed there

docker images

You will see something like:

REPOSITORY TAG IMAGE ID CREATED SIZE

oracle/database 19.3.0-ee 915764c34e05 2 days ago 7.75GB

oraclelinux 7-slim 0a28ba78f4c9 2 months ago 132MB


4 - Create docker persistent area for oradata
mkdir -p /opt/oracle/oradata

You should provide the oracle:db ids from the container while setting the ownership. It should be 54321:54322.

sudo chown -R 54321:54322 /opt/oracle
5 - Create docker container

This step is done only time

docker run --name oracle19c --network host -p 1521:1521 -p 5500:5500 -v /opt/oracle/oradata:/opt/oracle/oradata -v /opt/oracle/scripts/startup:/opt/oracle/scripts/startup oracle/database:19.3.0-ee

It takes time. To update the password of the DB system, run:

docker exec oracle19c ./setPassword.sh <password>

Normally we leave the password as "manager", so do:

docker exec oracle19c ./setPassword.sh manager

Note: You can now use this as if the Oracle is installed on localhost due to the ports update

6 - Update Oratab

Outside of the container you can now edit /opt/oracle/oradata/dbconfig/ORCLCDB/oratab and update it from:

ORCLCDB:/opt/oracle/product/19c/dbhome_1:N

to

ORCLCDB:/opt/oracle/product/19c/dbhome_1:Y
7 - Start/Stop Oracle container
docker start oracle19c
docker stop oracle19c

8 - Necessary Steps for Windchill docker
docker exec -ti oracle19c sqlplus system/manager@orclpdb1
SQL> alter pluggable database orclpdb1 open;

SQL> CREATE OR REPLACE TRIGGER open_pdbs
AFTER STARTUP ON DATABASE
BEGIN
EXECUTE IMMEDIATE 'ALTER PLUGGABLE DATABASE ALL OPEN';
END open_pdbs;
/

SQL> CREATE TABLESPACE "BLOBS" DATAFILE '/opt/oracle/oradata/ORCLCDB/blobs01.dbf' SIZE 1G AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED LOGGING EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO;

SQL> CREATE TABLESPACE "WCAUDIT" DATAFILE '/opt/oracle/oradata/ORCLCDB/wcaudit01.dbf' SIZE 1G AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED LOGGING EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO;

SQL> commit;