Docker installed
docker info
❯ docker info
Client:
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)
compose: Docker Compose (Docker Inc., 2.0.0-beta.1)
scan: Docker Scan (Docker Inc., v0.8.0)-
A Docker image is an immutable file that contains all files an application needs to run properly.
-
Docker images represent an application and its virtual environment at a specific point in time
-
Docker images are just "templated", they cannot start or run.
-
A Docker registry is a storage and distribution system for Docker images.
docker pull public.ecr.aws/bacardi/alpine:3.13.0
docker pull docker.io/library/alpine:3.13.0
docker pull alpine:latest
docker image ls
docker image rm public.ecr.aws/bacardi/alpine:3.13.0
docker image ls - A container is a runnable instance of an image
docker run --rm -i -t --name myalpine alpinedocker run -d --name alpine
docker container ls -adocker run -it --name testalpine alpineIn the container, run:
echo "hello" > world.txt
cat world.txtExit the container
check containers
docker container ls -a
docker start container testalpine
docker exec -it testalpine /bin/shCheck if you can find the file world.txt exit the container and delete the container
docker stop testalpine
docker rm testalpinedocker run -it --rm -name auto-delete-alpine alpine docker run -it --name alpine1 alpine
docker run -it --name alpine1 alpineBind mounts are dependent on the directory structure and OS of the host machine
docker run --rm -it -v /app -v ${PWD}:/myfolder alpine /bin/bashvolumes are completely managed by Docker.
docker volume create my-vol
docker volume ls
docker volume inspect my-vol
docker run --mount source=myvol,target=/myvolume alpine /bin/bash
docker volume rm my-voldocker run -it --rm -e NAME=nordine alpine
Without port forwarding, we can't reach the container
docker run -it --rm -d --name hello gcr.io/google-samples/hello-app:1.0
curl localhost:8080The first parameter is the port on the host and the second is the port on the container
docker run -it --rm -d -p 33333:8080 gcr.io/google-samples/hello-app:1.0
curl localhost:33333# create a volume to persist data
docker volume create db_data
# run the container
docker run -d --rm --name mysql -v db_data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=somewordpress -e MYSQL_DATABASE=wordpress -e MYSQL_USER=wordpress -e MYSQL_PASSWORD=wordpress mysql:5.7
#check the logs
docker logs mysql# create a volume to persist data
docker volume create wordpress_data
# run the container
docker run -d --rm --name wordpress --link mysql:db -p 8000:80 -v wordpress_data:/var/www/html -e WORDPRESS_DB_HOST=db:3306 -e WORDPRESS_DB_USER=wordpress -e WORDPRESS_DB_PASSWORD=wordpress -e WORDPRESS_DB_NAME=wordpress wordpress:latest
#check the logs
docker logs wordpressOpen Wordpress
open localhost:8000
Now delete all containers
cd docker-compose
docker-compose updocker-compose down cd dockerfiledocker build -t myalpine .docker run -it --rm myalpinedocker run -it --rm --entrypoint /bin/sh myalpine docker run -it --rm --entrypoint /bin/sh myalpinedocker run -d -p 5000:5000 --restart=always --name registry registry:2docker tag myalpine localhost:5000/myremotealpinedocker push localhost:5000/myremotealpinedocker pull localhost:5000/myremotealpine