Docker, developpment image and good practices concerning deployment

Hi

Context

Developpment context

I m a full new docker user, and I m actually acquiring the basis. Actually, I need to create a simple dev environnement using :

  • NodeJs
  • Mongodb

Production context

I need to create a production image (and if possible, the same used in my dev one) and to be able to pull data from git, when jenkins tells me to do it so. I’m actually using OpenSSH in my Docker image, and connect through RSA key between Jenkins and my Docker image, when a build successes.

Questions

Developpment context

  • How can I make changes inside my dockerfile code, directly from my “real os” ? I mean, each time I make a modification, I used to use nodemon to restart my app, so I can have informations displayed in the screen in close realtime. The code is now inside my docker container, and I dont know how to work, directly on it.

Production context

  • I wanted to know if my way is a good practice, or if it exists something better ?

Thanks for advance

Things look fine in your Production context. However, in your Development context, use Volume, which will allow you to make live changes from your host system using your favorite IDE or Text Editor. Furthermore, data volumes aren’t part of the container layered file system and will have the performance of your docker host file system.
With this approach, you may want to split your image into two: base and <other-image>. Your base image is which you use in both Dev and Production. You use, base with Volume option in your dev, whereas <other-mage> will have FROM base and have extra codes to pull the code-repo. This <other-image> is what you will use as is, in the production.
This is a very simplified view. I haven’t considered your linking of multiple containers with Docker Compose here.

Hi,

I’m also concerning about using docker in production.

  1. Should we keep database in docker image? or we keep database in host? which is better?
  • if keeping database in docker image:
    • can we use docker commit daily as backup solution?
    • what if the docker process is killed, current data will be lost?
  1. How do we do CI for docker image?
    Currently, I run docker image, then use Jenkins to automate deployment to docker container as the same as the way that I do with a real machine.
    is there any other better manner to do deployment with docker?

For the first part, I would create a database container ( with actual data in data container ) and link it to other containers using Docker Compose. This way your data persists even if the database container or other containers are killed.
The second part seems good to me but it depends how you are using your Jenkins job. As long as you are doing things efficiently, you should be good.

Thank you for answer.

Docker Compose is interesting. I will check it out for more.