Archive for the ‘Docker’ Category

Setting up Docker Client to connect to remote daemon using CLI

Sunday, October 29th, 2023

On Docker Daemon

IP: 192.168.100.100

user@docker:~$ sudo systemctl edit docker.service

ExecStart=/usr/bin/dockerd -H fd:// -H tcp://127.0.0.1:2375

user@docker:~$ sudo systemctl restart docker.service

user@docker:~$ sudo netstat -lntp | grep dockerd
tcp 0 0 127.0.0.1:2375 0.0.0.0:* LISTEN 170/dockerd

On Docker Client

user@client:~$ ssh-keygen

user@client:~$ ssh-copy-id 192.168.100.100

user@client:~$ docker context create node2
–description “Node 2” \
–docker “host=ssh: //$TARGET _HOST”

user@client:~$ docker context use node2

user@client:~$ docker ps

CONTAINER ID   IMAGE                        COMMAND                  CREATED          STATUS         PORTS                                       NAMES

0cf710e9fdbf   hello:2          “/docker-entrypoint.???”   12 minutes ago   Up 7 minutes   1883/tcp                                    container-1

Login to the container as root

Friday, October 7th, 2022
docker exec -it --privileged --user root container_id bash

Running a BusyBox container

Tuesday, March 1st, 2022

Running a temporary Linux Shell

docker run -it --rm busybox

Docker for Dummies

Friday, November 12th, 2021

Dockerfile

A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build users can create an automated build that executes several command-line instructions in succession.

FROM node:12-alpine
RUN apk add --update --no-cache python2 g++ make
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["node", "src/index.js"]

Build a docker image

docker build -t <container-image> .

Scan for vulnerabilities

docker scan  <container-image>

Start a container

docker run -dp <host-port>:<container-port> --name <container-name> <container-image> 

Removing a container

docker ps

docker stop <container-id>
docker remove <container-id>

or

docker rm -f <container-id>

Stop and removing all running containers

docker stop $(docker ps -q)docker rm $(docker ps -a -q)

Execute a command inside a container

docker exec 
-t tty
-i interactive
docker exec <container-id> <cmd>
docker exec -i <container-name> <cmd>

start a shell in a container

docker exec -it <container-name> /bin/bash

Create a Persistence Volume

docker volume create <volume-name>

start a container with persistence volume – Named Volume

docker run -dp <host-port>:<container-port> -v <pv-volume-name>:<container-path> <container-image>

after docker v 17.0.6

docker run -dp <host-port>:<container-port> --mount type=<pv-volume-name>,source=<pv-volume-name>,target=<containter-path> <container-image>

create a named volume

docker create volume <volume-name>

Remove a named volume

docker volume rm <volume-name>

list persistence volume in docker – Named Volume

docker volume ls 

start a container with persistence volume – Binded Volume

docker run -dp <host-port>:<container-port> -v <host-path>:<container-path> <container-id>

after docker v 17.0.6

docker run -dp <host-port>:<container-port> --mount type=bind,source=<host-path>,target=<container-path> <container-id>

showing the console log

docker logs -f <container-id>

Create a dedicated network between app container and mysql container

docker create network <network-name>

docker run -d \
	--name <container-name> \
	--network <network-interface-name> \
	--network-alias <host-name> \
	--mount type=bind,source=<host-path>,target=<container-path> \
	-e MYSQL_ROOT_PASSWORD=<db-password> \
	-e MYSQL_DATABASE=<db-name> \
	<docker-image>

docker run -it -p 3000:3000 \
	--name <container-name> \
	--network <network-interface-name> \
	-e MYSQL_HOST=<db-host> \
	-e MYSQL_USER=<db-user> \
	-e MYSQL_PASSWORD=<db-password> \
	-e MYSQL_DB=<db-name> \
	<container-image>

Start a Network Troubleshooting container

docker run -it --network <network-interface-name> nicolaka/netshoot