Run directly or in docker container

Containerization is a technology that allows you to package an application along with its dependencies and runtime environment into a self-contained unit called a container. Docker provides tools and a runtime environment to create, deploy, and manage containers efficiently.

The advantages and disadvantages of Docker:

Advantages of DockerDisadvantages of Docker
Isolation and PortabilityLearning Curve
Efficiency and Resource UtilizationResource Overhead
Version Control and ReproducibilitySecurity Concerns
DevOps and CI/CDComplexity in Orchestration
Ecosystem and Community SupportDisk Space and Image Management
Docker CommandDescription
docker run [OPTIONS] IMAGERun a new container from a specified image.
docker build [OPTIONS]Build a Docker image from a Dockerfile.
docker push [OPTIONS]Push a Docker image to a registry (e.g., Docker Hub).
docker pull [OPTIONS]Pull a Docker image from a registry (e.g., Docker Hub).
docker ps [OPTIONS]List running containers.
docker ps -a [OPTIONS]List all containers (including stopped ones).
docker start [OPTIONS]Start a stopped container.
docker stop [OPTIONS]Stop a running container.
docker rm [OPTIONS]Remove one or more containers.
docker images [OPTIONS]List Docker images.
docker rmi [OPTIONS]Remove one or more images.
docker exec [OPTIONS]Run a command inside a running container.
docker-compose [COMMAND]Manage multi-container Docker applications using Docker Compose (e.g., up, down, build).
docker logs [OPTIONS]View logs from a container.
docker inspect [OPTIONS]Display detailed information about a container, image, network, or volume.
docker network [COMMAND]Manage Docker networks (e.g., create, ls, connect).
Install docker in debian linux
bash <(curl -sSL https://get.docker.com)

Uninstall docker in debian linux

apt-get purge docker-ce -y
apt-get autoremove --purge docker-ce -y
rm -rf /etc/docker
rm -rf /var/lib/docker

Here is an example to run a program directly and run in a docker container. We assume the program name is xxx.

#run directly 

ARCH=$(uname -m)
case "${ARCH}" in
  x86_64 | x64 | amd64) MY_ARCH="amd64" ;;
  i*86 | x86) MY_ARCH="386" ;;
  armv8* | armv8 | arm64 | aarch64) MY_ARCH="arm64" ;;
  armv7* | armv7) MY_ARCH="armv7" ;;
  armv6* | armv6) MY_ARCH="armv6" ;;
  armv5* | armv5) MY_ARCH="armv5" ;;
  *) MY_ARCH="amd64" ;;
esac

wget https://github.com/your/program/releases/latest/download/xxx-linux-${MY_ARCH}.tar.gz

cd /root/
rm -rf xxx/ /usr/local/xxx/ /usr/bin/xxx
tar zxvf xxx-linux-${XUI_ARCH}.tar.gz
chmod +x xxx/xxx xxx/bin/xxx-linux-* xxx/xxx.sh
cp xxx/xxx.sh /usr/bin/xxx
cp -f xxx/xxx.service /etc/systemd/system/
mv xxx/ /usr/local/
systemctl daemon-reload
systemctl enable xxx
systemctl restart xxx

#run in a docker container

docker run -itd \
   -v $PWD/db/:/etc/xxx/ \
   -v $PWD/cert/:/root/cert/ \
   --network=host \
   --restart=unless-stopped \
   --name xxx \
   your/image/xxx:latest

docker logs xxx        #to see the logs
docker exec -it /bin/bash     #start a shell in the container

To update your Docker container to use the updated image

docker container update --image <image-name>:<tag> <container-name>

Leave a Comment