5

I have a project that is running in local development using docker-compose

As part of the organisation requirements for gitlab and deployment, the application needs to be built into a single Docker image.

I understand this can be done by adding a Dockerfile to the project.

However, I'm wondering if any advice or suggestions on how to include a project running multiple services via docker-compose with the application codebase into a single image with Dockerfile for deployment, thanks.

EDIT: From what I can gather, the approach would be to build a new image , with Dockerfile, from the application codebase, then include that in the docker-compose.yml file for the deployment environment?

EDIT 2: Apologies for the confusion. I'm new at Docker and there's a bit of learning curve! In this case it seems one can build the application image in the gitlab registry and then include that image in the docker-compose for deployment, will try it.

2
  • Without seeing your docker-compose.yml file it's going to be very difficult to answer this question. There are some things that simply don't translate. Moving from docker-compose to a single Dockerfile will probably increase the complexity of your project.
    – larsks
    Commented Dec 13, 2017 at 0:07
  • @larsks thanks for your response. I've added more details on the docker-compose.yml file. Please check if that helps on how to convert it to a Dockerfile for the project Commented Dec 13, 2017 at 0:13

1 Answer 1

10

TL;DR

A single Dockerfile is usually not enough to replace a whole containers orchestration made with docker-compose and is not necessarly a good choice.

About converting a docker-compose.yml file to a Dockerfile :

You can pass some informations from your docker-compose.yml file to your Dockefile (the command to run for instance) but that wouldn't be equivalent and you can't do that with all the docker-compose.yml file content.

You can replace your docker-compose.yml file with commands lines though (as docker-compose is precisely to replace it).


BUT

Keep in mind that Dockerfiles and docker-compose serve two whole different purposes.

  • Dockerfile are meant for image building, to define the steps to build your images.

  • docker-compose is a tool to start and orchestrate containers to build your applications (you can add some informations like the build context path or the name for the images you'd need, but not the Dockerfile content itself).

So asking to "convert a docker-compose.yml file into a Dockerfile" isn't really relevant.

That's more about converting a docker-compose.yml file into one (or several) command line(s) to start containers by hand.

The purpose of docker-compose is precisely to get rid of these command lines to make things simpler (it automates it).

Multiple processes in a single container :

From the docker documentation :

It’s ok to have multiple processes, but to get the most benefit out of Docker, avoid one container being responsible for multiple aspects of your overall application

So you can if your entrypoint permits you to launch several processes, or if you use a supervisor, but maybe that's not necessarly the best idea.

EDIT

Since I'm not sure it's clear for you either, here is the difference between a container and an image.

You really should check this out and try to understand this before working with Docker since it's a very necessary thing to know.

9
  • Thanks for your response. Yes, I understand docker-compose and the dockerfile serve different purposes. In this case it is an org requirement to flatten the project to a single image for gitlab CD deployment. So, to build the project image from the Dockerfile, I would need to take the commands from the docker-compose file and convert into Dockerfile syntax? Commented Dec 13, 2017 at 0:09
  • @DavidThomas No, you didn't get the difference between Dockerfiles and docker-compose.yml files. You should really look it up. The answer I linked is also great to explain the difference between both. The steps you provide in the Dockerfile are meant for the images building process. The informations you provide in the docker-compose.yml file are meant to tell compose how to start these containers.
    – vmonteco
    Commented Dec 13, 2017 at 0:19
  • OK thanks, yes I've read the docs and I'm not sure that's any clearer. Perhaps I can find a way to just use the docker-compose.yml file only. I'm not sure why the Dockerfile is needed when the project is already running with docker-compose however the aim is to use Dockerfile to build an image of the whole project for deployment Commented Dec 13, 2017 at 0:20
  • How do you build your images if you don't have a base image that fits your need nor a Dockerfile to build your image from a base image then?
    – vmonteco
    Commented Dec 13, 2017 at 0:22
  • 1
    Well, that's the question, how can I build the project image from the docker-compose services + application code base? Trying to work out what's required for the Dockerfile there. Commented Dec 13, 2017 at 0:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.