- 1. Whats is docker and containers?
- 2. Instalation in Windows 10
- 3. Docker commands
- 4. Dockerfile structure
- 5. Docker compose
- 6. Access Docker using REST API or Expose docker remotely
- 7. Docker images
- 8. Grafana
- 9. Graphite / Statds
- 10. Extras
- Docker is an open platform for developing, shipping, and running applications.
- Docker provides to separate your applications from your infrastructure so you can deliver software quickly.
- Docker is a software development platform to deploy apps.
- Apps are packaged in containers that can be run on any OS.
- Apps run the same, regardless of where they're run:
- Any machine.
- No compatibility issues.
- Predictable behavior.
- Less work.
- Easier to maintain and deploy.
- Works with any language, any OS, any technology.
- Use cases: microservices architecture, lift-and-shift apps from on-premises to the AWS cloud, ...
- Methodologies for shipping, testing, and deploying code quickly, you can significantly reduce the delay between writing code and running it in production.
- Docker provides for automating the deployment of applications as portable, self-sufficient containers that can run on the cloud or on-premises.
- Docker containers can run anywhere, in your local computer to the cloud.
- Docker image containers can run natively on Linux and Windows.
- A container is a standard unit of software that packages up code and all its dependencies so, the application runs quickly and reliably from one computing environment to another.
- A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application.
- All informations about docker in the machine
- docker info
- Show the Docker version information
- docker --version
- Create container by image
- docker create --name
<container_name>
<image_name>
- docker create --name
- Show running containers (Process status)
- docker ps
- docker ps -a # Show all
- docker container ls -a
- docker container ps -a
- List all images in local repository
- docker images
- Pull (download) an image or a repository from a registry
- docker pull
<image_name>:<version>
or<tag>
# Example docker pull hello-world:latest
- docker pull
- Rum a command to start a container
- docker start
<container_name>
- docker start
- Rum a command to stop a container
- docker stop
<container_name>
- docker stop
- Create and run the container, this command eliminates the need to run
docker create
and thendocker start
- docker run
<image_name>
# Example docker run hello-world - docker run -d
<image_name>
# -d Detach, run container in background and print container ID - docker run -d -p
<external_port:internal_docker_port>
<image_name> or <tag_name>
- docker run -it --rm
<image_name>
# Run and delete the container when the container stops
- docker run
- Remove image
- docker image rm
<image_name>
or<image_id>
# Example docker image rm hello-world:latest
- docker image rm
- Remove container
- docker container rm
<container_name>
or<container_id>
- docker container rm
- Docker attach commands to start the container and peek at the output stream
- docker attach --sig-proxy=false core-counter
<container_name>
- docker attach --sig-proxy=false core-counter
- Fetch the logs of a container
- docker logs -f
<image_name>
# Log live
- docker logs -f
- Run a command in a running container
- docker exec -it
<container_name>
bash # -it --interactive and --tty - docker exec -it -u root
<container_name>
bash # With user root
- docker exec -it
- Copy files/folders between a container and the local filesystem
- docker cp
<file_name>
<container_name>
:<path>
/<file_name>
# Example: docker cp script.sh myContainer:/tmp/script.sh
- docker cp
- Build Dockerfile
- docker build .
- docker build --tag
<tag_name>
.
-
FROM
# Fully qualified Docker container image name -
COPY
# Copy the specified folder on your computer to a folder in the container -
WORKDIR
# Changes the current directory inside of the container to App -
ENTRYPOINT
# Tells Docker to configure the container to run as an executable -
Example of Dockerfile example to build a dotnet project.
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build-env WORKDIR /my_custom_path_build_env COPY . ./ # Run this command to see result of commands ls... docker build --no-cache --progress plain . RUN echo $(ls) RUN dotnet restore RUN dotnet publish -c Release -o publish RUN echo $(ls ./publish) FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS stage-env WORKDIR /my_custom_path_stage_env COPY --from=build-env /my_custom_path_build_env/publish . RUN echo $(ls) EXPOSE 80 ENTRYPOINT ["dotnet", "My.dll"]
- All informations about docker compose in the machine
- docker-compose version
- Create/Recreate and start containers, use docker-compose.yml
- docker-compose up -d
- docker-compose up -d
<name_service>
- Build or rebuild services
- docker-compose build
- docker-compose build
<name_service>
# Build specific image.
- Starts existing containers for a service.
- docker-compose start
- Stop all containers
- docker-compose stop
- Docker
- compose-build
- Remove all containers and images
docker-compose down docker rm -f $(docker ps -a -q) docker volume rm $(docker volume ls -q) docker rmi -f $(docker images -a -q)
version: '3'
services:
my_service:
container_name: CONTAINER_NAME
image: IMAGE_NAME
ports:
- "8080:8080"
volumes:
- "$PWD/HOME:/VAR/PATH_HERE"
networks:
- net
networks:
net:
- ps -ef | grep docker
- sudo nano /lib/systemd/system/docker.service
- Replace line ExecStart=*** to ExecStart=/usr/bin/dockerd -H fd:// -H=tcp://0.0.0.0:2375
- sudo systemctl daemon-reload
- sudo service docker restart
- Test with url http://address:2375/images/json or http://address:2375/containers/json
7.1. RabbitMQ (http://localhost:15672/)
- docker pull rabbitmq:3-management
- docker run -d -p 15672:15672 -p 5672:5672 --name rabbit_dev rabbitmq:3-management
- docker run -d -p 5672:5672 -p 15672:15672 --name rabbitmq_dev rabbitmq:3.9-management
- Default user and password: guest/guest
- docker pull mcr.microsoft.com/mssql/server:2019-latest
- docker run -d -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=yourStrong(!)Password" --name ordermssql -p 1445:1433 mcr.microsoft.com/mssql/server:2019-latest
- docker pull jenkins/jenkins
- docker run -p 8080:8080 jenkins/jenkins -- name jenkins_dev
- sudo docker exec -it gitlab_dev grep 'Password:' /etc/gitlab/initial_root_password
- sudo gitlab-rake "gitlab:password:reset[root]"
- docker pull mongo
- docker run -d -p 27017:27017 --name mongo_dev mongo
- docker exec -it mongo_dev bash
- docker pull redis
- docker run -d -p 6379:6379 --name redis_dev redis
- docker run --name postgres_dev -p 5432:5432 -e POSTGRES_PASSWORD=mysecretpassword -d postgres
- docker run -d --name=grafana -p 3000:3000 grafana/grafana
- docker run -d --name graphite --restart=always -p 80:80 -p 2003-2004:2003-2004 -p 2023-2024:2023-2024 -p 8125:8125/udp -p 8126:8126 graphiteapp/graphite-statsd
- Specific command to dotnet applications
- docker build -f API\Dockerfile . -t
<image_name>
- docker run -p 500:80 -t
<image_name>
- docker build --no-cache --progress plain .
- docker build -f API\Dockerfile . -t