Skip to content

Docker & Docker Compose

Mehdi Hadeli edited this page Jun 12, 2023 · 41 revisions

Docker

Articles

Videos

Notes

  • use docker exec -it docker-remote-debugging bash for interacting with container`
  • We could use also a predefined network and connect to that predefined network with specifying the name of existing network and set external attribute to true
  • When we run docker-compose up, Docker Compose will check if the 'ecommerce' network already exists. If it does not exist, it will create the 'ecommerce' network. If it exists, it will use the existing 'ecommerce' network. Problem is that if we do a docker-compose down this network will delete and other docker-compose that use same network will fail because network deleted, so it's better we use external keyword for using a predefined network
  • We can use the network that will create by infrastructure docker-compose and use this network in other docker-compose files with the name of existing network and set external attribute to true for using network that defined outside our docker-compose file. Also, We can create a ecommerce network manually by docker network create -d bridge ecommerce and use this network as external network for all docker-compose files
  • Using the base image of the Dockerfile for debugging can be more efficient because you don't need to build the entire application from scratch. Instead, you can reuse the already-built layers and add debugging tools and configurations as needed. This can save time and resources, especially if your application is large or complex.
  • On the other hand, doing a full build for debugging can ensure that the debugging environment is identical to the production environment. This can help catch issues that may not surface in a modified version of the image, and provide a more accurate representation of the production environment. However, this approach can be slower and require more resources.
  • we can supply multiple -f configuration files. When you supply multiple files, Compose combines them into a single configuration. Compose builds the configuration in the order you supply the files. Subsequent files override and add to their predecessors.
  • if we use base image directly for running our mapped debug dll (not published dll, with publish dll depdendent assmblies are there also) it deosn't have all dependet assmblies and in this layer or stage we don't have nugets so we can get nugets that mapped from host machine with volume in docker run or docker-compose up and pass it to --additionalProbingPath in lunching program. for example dotnet <application.dll> --additionalProbingPath /root/nuget/packages --additionalProbingPath ~/.nuget/packages
  • we can use mounted volume in docker run or docker-compose up for a entrypoint in dockerfile when docker container will be run for the host with --mount type=bind,source=${env:USERPROFILE}\\.nuget\\packages,destination=/root/.nuget/packages,readonly. for example dotnet <application.dll> --additionalProbingPath /root/nuget/packages
  • When we use multi stage build, docker build uses last stage as output of build and created image and also we can remove intermediat layers that uses for create final stage with using docker image prune -f
  • for setup dev certificate on ubuntu we can use this approuch, dotnet dev-certs https --trust is only supported on macOS and Windows but we don't get error in our applications and It is likely that you need to trust the certificate in your browser and allow process with none trusted cert.
dotnet dev-certs https -ep ${HOME}/.aspnet/https/aspnetapp.pfx -p <CREDENTIAL_PLACEHOLDER>
dotnet dev-certs https --trust

Also if we use WSL we can use this approuch:

The easiest way to have Windows trust the WSL certificate, is to configure WSL to use the same certificate as Windows, On Windows, we generate a certificate and shaare it for use in wsl:

dotnet dev-certs https -ep https.pfx -p $CREDENTIAL_PLACEHOLDER$ --trust

Then we open wsl, and Import this generated windows cert in our wsl:

dotnet dev-certs https --clean --import https.pfx --password $CREDENTIAL_PLACEHOLDER$

Samples

Docker Compose

Articles

Notes

  • Substitute for replacing evnironment only support from .env file substitute and shell substitute for reading shell based environemnts
  • Substitute env files and repacing inner docker-compose files with --env-file and pass the file as an argument in the CLI, If the --env-file is not used in the command line, the .env file is loaded by default(docker compose --env-file ./config/.env.dev up)
Clone this wiki locally