Using docker

Docker is a recommended container platform for running applications such as mongodb, rabbitmq used in the DevPrime demo (Windows, Linux, macOS).

The use of containers in the Docker facilitates the day-to-day life of the software developer person, as it becomes very easy to climb services such as database, messenger services, caching services and other important tools that we use on a day-to-day and can be installed with simplicity and later removed after use.

In the initial demos we used MongoDB and RabbitMQ and so you should go up these two services in Docker. If you already have one of the services running just change the credentials in the verification file.
code /src/App/app/appsettings.json

Logging in to Docker.
docker login -u <user> -p <password>

Creating a virtual network in Docker
In our demos we will use a virtual network ‘devprime’ by unifying communication between all containers used. Use the create command.

  • Creating a virtual devprime network
    docker network create devprime
  • Listing existing networks
    docker network list
  • Deleting a virtual network
    docker network rm devprime

Starting containers in Docker
A basic example involves at least one mongodb container and one RabbitMQ container. Copy the line below and run to start the container in Docker.

Item Tool Command
1 MongoDB docker run --network devprime --name mongodb -p 27018:27018 -p 27019:27019 -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=mongoadmin -e MONGO_INITDB_ROOT_PASSWORD=LltF8Nx*yo -d mongo
2 RabbitMQ docker run --network devprime --name rabbitmq -d -p 5672:5672 -p 15672:15672 -t rabbitmq:3-management
3 MySQL docker run -d --network devprime --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=LltF8Nx*yo mysql:8.0
4 SQLServer docker run -d --network devprime --name sqlserver -e “MSSQL_SA_PASSWORD=LltF8Nx*yo”-e “ACCEPT_EULA=Y” -p 1433:1433 mcr.microsoft.com/mssql/server
5 PostgreSQL docker run -d --network devprime --name postgresql -p 5432:5432 -e POSTGRES_PASSWORD=LltF8Nx*yo postgres:alpine3.14
6 Redis docker run --network devprime --name redis -p 6379:6379 -e REDIS_PASSWORD=LltF8Nx*yo -d redis

Starting queue confining in RabbitMQ
DevPrime-based microservices automatically connect to Stream services such as RabbitMQ.

  1. Open Rabbitmq in the browser in http://localhost:15672
  2. Use user and password guest /guest defaults
  3. Go to the Queue > Add a new queue > “orderevents”
    Configurando filas no RabbitMQ
  4. Repeat the step in item 3 and add “paymentevents”

The names of queues or topics are used in the DevPrime examples. Along
of the projects you will define other names.

Stopping containers and removing docker images
In this topic we present some basic docker commands to remove containers and even clean up all local images. The last option of prune is very useful for cleaning all docker.

Item Command Objective
1 docker kill $(docker ps -a -q) Stop containers
2 docker rm $(docker ps -a -q) Remove containers
3 docker rmi $(docker images -q) Remove images
4 docker system prune --volumes -f -a Clear multiple dependencies
Last modified March 25, 2022 (f805581)