Basic:
# Install:
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine \
podman \
runc
sudo yum install -y yum-utils
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/rhel/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
sudo systemctl enable docker
sudo systemctl start docker
# Download 1 image:
docker pull rockylinux:8.7
# Show all images:
docker images
# Create new container from 1 image then run:
docker run -d -p 3000:22 -p 3001:3306 -t --name "RockyTest01" rockylinux:8.7
# Show all containers
docker ps -a
# Open terminal in a running container with status "Up":
docker exec -it [containerId] /bin/bash
# Example:
docker exec -it ed734a9f59ee /bin/bash
Build from OS and your apps
# Do not use an existing image, but create it directly from the operating system OS with a nodejs application
## Install nodejs if not already installed
### Find version
dnf module list nodejs
### Install version, for example:
dnf module install nodejs:16
## Create a test application folder
mkdir test && cd test
## Create a test js app that runs on network interfaces (0.0.0.0)
tee index.js <<EOF
const http = require('http');
const hostname = '0.0.0.0';
const port = 8080;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
EOF
## Create Dockerfile to build image
tee Dockerfile <<EOF
FROM node:16-alpine
ENV NODE_ENV=production
WORKDIR /app
COPY . /app
EXPOSE 8080
CMD node index.js
EOF
## Build image to run the js app above
docker build . -t test01/hello
## Run the container from that image, go to the opened port 8080 of the container
docker run -d -t -p 3000:8080 --name "testku01" test01/hello
## Try to see if it's ok:
curl localhost:3000