Getting into docker a bit deeper

  • I’ve got an asp.net core app that I’m creating and I’ve used docker to setup and deploy the app a bit more easily
  • To build the asp.net app, I’ve got a single Dockerfile which looks as follows:
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /source

COPY . .
RUN dotnet publish -o /app

# final stage/image
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT ["dotnet","mywebapp-dotnet.dll"]
  • This asp.net app also makes use of a postgresql database so in order to get them both up and running I’ve made use of docker compose using the file docker-compose.yml. The compose file looks as follows:
services:
  web:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "8123:8080"
    links:
      - "db:mywebapp-dotnet-db-1"
    environment:
      DBCONSTR: Host=mywebapp-dotnet-db-1;Database=mywebapp;Username=postgres;Password=mysecretpassword
    volumes:
      - mywebapp_logs:/var/logs/mywebapp

  db:
    image: postgres
    restart: always
    # set shared memory limit when using docker-compose
    shm_size: 128mb
    # or set shared memory limit when deploy via swarm stack
    #volumes:
    #  - type: tmpfs
    #    target: /dev/shm
    #    tmpfs:
    #      size: 134217728 # 128*2^20 bytes = 128Mb
    environment:
      POSTGRES_PASSWORD: mysecretpassword
      PGDATA: /var/lib/postgresql/data/mywebapp
    volumes:
      - mywebapp_data:/var/lib/postgresql/data/mywebapp

volumes:
  mywebapp_data:
  mywebapp_logs:
  • Some observations on the above docker compose file:
    • Volumes: In order to get data for logs and the postgresql database available from the host machine I needed to create these named volumes
    • Networking: By default docker creates a network with a unique id to allow the various services defined in the docker compose file to talk to each other. Making use of the unique id to point the asp.net core app to the postgresql db service will not be reliable as this value will be different every time the containers are recreated or will be different on different host machines (e.g. local dev vs production). There seems to be many different ways of addressing this in docker, however, I’ve taken the easiest approach of adding in the “link” property to the asp.net core service definition. The link property maps the service name to an alias, and with the way docker works, it’s able to translate the alias to the postgresql database host. Therefore I can make use of the alias in the DB connection string as well.

Posted

in

by

Tags:

Comments

28 responses to “Getting into docker a bit deeper”

  1. binance anm"alningsbonus Avatar

    Your point of view caught my eye and was very interesting. Thanks. I have a question for you.

  2. ck777plataforma Avatar

    Alright, ck777plataforma’s got a clean look to it. Depositing was easy. A pretty good place to try and win some cash when you’re bored! Go see for yourself: ck777plataforma

  3. shbet800com Avatar

    Yo, just finished playing at shbet800com. Pretty standard stuff, decent payout times. Also the site has a cool theme. Worth a look, I think. Find more clicking here: shbet800com

  4. 6789fccom Avatar

    I gotta say, 6789fccom has a lot going for it. Good offers, the games are very varied, and you can just keep playing forever! The world’s your oyster! Check it out, you won’t regret doing the same: 6789fccom

  5. binance konto skapande Avatar

    Your point of view caught my eye and was very interesting. Thanks. I have a question for you.

  6. Ralphacuct Avatar
    Ralphacuct

    I express gratitude for the help in this question.

    _ _ _ _ _ _ _ _
    car hire casablanca

  7. dutasteride prescription canada

    dutasteride prescription canada

  8. registrera dig f"or binance Avatar

    Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?

  9. cap vibramycin

    cap vibramycin

  10. Eugenelumma Avatar
    Eugenelumma

    You are definitely right

    _ _ _ _ _ _ _ _
    https://automietenlapalma.de

  11. binance signup Avatar

    Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?

  12. Cod Binance Avatar

    Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.

  13. Binance代码 Avatar

    Your point of view caught my eye and was very interesting. Thanks. I have a question for you.

  14. tadalafil dosage 40 mg

    tadalafil dosage 40 mg

  15. vidalista 10mg uses

    vidalista 10mg uses

  16. www.binance.info注册 Avatar

    Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?

  17. gratis binance-konto Avatar

    Thanks for sharing. I read many of your blog posts, cool, your blog is very good. https://www.binance.com/register?ref=IXBIAFVY

  18. binance anm"alan Avatar

    Your point of view caught my eye and was very interesting. Thanks. I have a question for you.

  19. stendra 200 mg tablet

    stendra 200 mg tablet

  20. BRAND NEW PORN SITE SEX Avatar

    Stream adult content safely by choosing verified adult websites.
    Opt for reliable sources for discreet entertainment.

    Here is my web blog … BRAND NEW PORN SITE SEX

  21. finasteride manufacturer

    finasteride manufacturer

  22. tadalafil buy

    tadalafil buy

  23. target rogaine shampoo

    target rogaine shampoo

  24. Binance推荐代码 Avatar

    Thanks for sharing. I read many of your blog posts, cool, your blog is very good.

  25. 最佳Binance推荐代码 Avatar

    Your point of view caught my eye and was very interesting. Thanks. I have a question for you.

Leave a Reply

Your email address will not be published. Required fields are marked *