Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a Dockerfile to a docker compose image?

This is how I'm creating a docker image with nodeJS and meteorJS based on an ubuntu image. I'll use this image to do some testing.

Now I'm thinking of doing this via docker compose. But is this possible at all? Can I convert those commands into a docker compose yml file?

FROM ubuntu:16.04

COPY package.json ./

RUN apt-get update -y && \
    apt-get install -yqq \
        python \
        build-essential \
        apt-transport-https \
        ca-certificates \
        curl \
        locales \
        nodejs \
        npm \
        nodejs-legacy \
        sudo \
        git

## NodeJS and MeteorJS
RUN curl -sL https://deb.nodesource.com/setup_4.x | bash -
RUN curl https://install.meteor.com/ | sh

## Dependencies
RUN npm install -g eslint eslint-plugin-react
RUN npm install

## Locale
ENV OS_LOCALE="en_US.UTF-8"
RUN locale-gen ${OS_LOCALE}
ENV LANG=${OS_LOCALE} LANGUAGE=en_US:en LC_ALL=${OS_LOCALE}

## User
RUN useradd ubuntu && \
    usermod -aG sudo ubuntu && \
    mkdir -p /builds/core/.meteor /home/ubuntu && \
    chown -Rh ubuntu:ubuntu /builds/core/.meteor && \
    chown -Rh ubuntu:ubuntu /home/ubuntu
USER ubuntu
like image 836
user3142695 Avatar asked May 17 '17 23:05

user3142695


People also ask

Is Dockerfile same as Docker compose?

The key difference between the Dockerfile and docker-compose is that the Dockerfile describes how to build Docker images, while docker-compose is used to run Docker containers.

Can I use Docker compose instead of Dockerfile?

Docker Compose (herein referred to as compose) will use the Dockerfile if you add the build command to your project's docker-compose. yml . Your Docker workflow should be to build a suitable Dockerfile for each image you wish to create, then use compose to assemble the images using the build command.


1 Answers

Docker Compose doesn't replace your Dockerfile, but you can use Docker Compose to build an image from your Dockerfile:

version: '3'
services:
  myservice:
    build:
      context: /path/to/Dockerfile/dir
      dockerfile: Dockerfile
    image: result/latest

Now you can build it with:

docker-compose build

And start it with:

docker-compose up -d
like image 113
Brian from QuantRocket Avatar answered Oct 20 '22 22:10

Brian from QuantRocket