-1

I have an existing docker-compose file

version: '3.6'
services:

  verdaccio:
    restart: always
    image: verdaccio/verdaccio
    container_name: verdaccio
    ports:
      - 4873:4873
    volumes:
      - conf:/verdaccio/conf
      - storage:/verdaccio/storage
      - plugins:/verdaccio/plugins
    environment:
      - VERDACCIO_PROTOCOL=https

networks:
    default:
        external:
            name: registry

I would like to use an DockerFile instead of docker-compose as it will be more easy to deploy DockerFile on an Azure container registry.

I have tried many solution posted on blogs and others but nothing worked as I needed.

How can I create simple DockerFile from the above docker-compose file?

4 Answers4

2

You can't. Many of the Docker Compose options (and the equivalent docker run options) can only be set when you start a container. In your example, the restart policy, published ports, mounted volumes, network configuration, and overriding the container name are all runtime-only options.

If you built a Docker image matching this, the most you could add in is setting that one ENV variable, and COPYing in the configuration files and plugins rather than storing them in named volumes. The majority of that docker-compose.yml would still be required.

David Maze
  • 130,717
  • 29
  • 175
  • 215
0

If you want to put conf, storage and plugins files/folders into image, you can just copy them:

FROM verdaccio/verdaccio
WORKDIR /verdaccio
COPY conf conf
COPY storage storage
COPY plugins plugins

but if you need to keep files/and folder changes, then you should keep them as it is now.

Giga Kokaia
  • 879
  • 8
  • 15
0

docker-compose uses an existing image.

If what you want is to create a custom image and use it with your docker-compose set up this is perfectly possible.

  1. create your Dockerfile - example here: https://docs.docker.com/get-started/part2/
  2. build an "image" from your Dockerfile: docker build -f /path/to/Dockerfile -t saurabh_rai/myapp:1.0 this returns an image ID something like 12abef12
  3. login to your dockerhub account (saurabh_rai) and create a repo for the image to be pushed to (myapp)
  4. docker push saurabh_rai/myapp:1.0 - will push your image to hub.docker.com repo for your user to the myapp repo. You may need to perform docker login for this to work and enter your username/password as usual at the command line.
  5. Update your docker-compose.yaml file to use your image saurabh_rai/myapp:1.0

example docker-compose.yaml:

version: '3.6'
services:

  verdaccio:
    restart: always
    container_name: verdaccio
    image: saurabh_rai/myapp:1.0
    ports:
      - 4873:4873
    volumes:
      - conf:/verdaccio/conf
      - storage:/verdaccio/storage
      - plugins:/verdaccio/plugins
    environment:
      - VERDACCIO_PROTOCOL=https
    network:
      - registry
Rob Evans
  • 2,822
  • 1
  • 9
  • 15
  • actually I have an existing project which uses docker compose file and that has been deployed on Virtual machine and now I need to migrate the entire code base to Azure app service that is why I need to convert it into DockerFile in such as way the history of the code base must be the same. As Azure still fully doesn't support compose file deployment. I only have option on DockerFile – SAURABH RAI May 11 '20 at 10:38
  • The answer lies in the difference between dockerfile, image & a container. A docker-compose file is more of a configuration file that lets you up one or multiple containers with different dependencies and settings. Be it restart policy or the port, they all come into picture only in case of a container. However, you can create a custom image by using some base image(s) in your dockerfile. – Aman May 11 '20 at 11:28
  • You don't really work in from `docker-compose` -> `Dockerfile`. Typically we produce a `Dockerfile` -> build image -> use image in `docker-compose.yaml` and provide config at runtime so a single image can be configured and run in dev, test or production. Since you ask, you *could* create an image but it becomes far less reusable. For instance, you're mounting volumes that change. If you're happy for the content to be static, you can copy the contents of directories into your image using `COPY src/ dest/` in your `Dockerfile`. Do the same for env vars, etc. – Rob Evans May 11 '20 at 16:25
0

I have solve this issue by using an existing verdaccio DockerFile given below.

FROM node:12.16.2-alpine as builder

ENV NODE_ENV=production \
    VERDACCIO_BUILD_REGISTRY=https://registry.verdaccio.org

RUN apk --no-cache add openssl ca-certificates wget && \
    apk --no-cache add g++ gcc libgcc libstdc++ linux-headers make python && \
    wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub && \
    wget -q https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.25-r0/glibc-2.25-r0.apk && \
    apk add glibc-2.25-r0.apk

WORKDIR /opt/verdaccio-build
COPY . .

RUN yarn config set registry $VERDACCIO_BUILD_REGISTRY && \
    yarn install --production=false && \
    yarn lint && \
    yarn code:docker-build && \
    yarn cache clean && \
    yarn install --production=true



FROM node:12.16.2-alpine
LABEL maintainer="https://github.com/verdaccio/verdaccio"

ENV VERDACCIO_APPDIR=/opt/verdaccio \
    VERDACCIO_USER_NAME=verdaccio \
    VERDACCIO_USER_UID=10001 \
    VERDACCIO_PORT=4873 \
    VERDACCIO_PROTOCOL=http
ENV PATH=$VERDACCIO_APPDIR/docker-bin:$PATH \
    HOME=$VERDACCIO_APPDIR

WORKDIR $VERDACCIO_APPDIR

RUN apk --no-cache add openssl dumb-init

RUN mkdir -p /verdaccio/storage /verdaccio/plugins /verdaccio/conf

COPY --from=builder /opt/verdaccio-build .

ADD conf/docker.yaml /verdaccio/conf/config.yaml

RUN adduser -u $VERDACCIO_USER_UID -S -D -h $VERDACCIO_APPDIR -g "$VERDACCIO_USER_NAME user" -s /sbin/nologin $VERDACCIO_USER_NAME && \
    chmod -R +x $VERDACCIO_APPDIR/bin $VERDACCIO_APPDIR/docker-bin && \
    chown -R $VERDACCIO_USER_UID:root /verdaccio/storage && \
    chmod -R g=u /verdaccio/storage /etc/passwd

USER $VERDACCIO_USER_UID

EXPOSE $VERDACCIO_PORT

VOLUME /verdaccio/storage

ENTRYPOINT ["uid_entrypoint"]

CMD $VERDACCIO_APPDIR/bin/verdaccio --config /verdaccio/conf/config.yaml --listen $VERDACCIO_PROTOCOL://0.0.0.0:$VERDACCIO_PORT

By making few changes to the DockerFile I was able to build and push my docker image to azure container registry and deploy to an app service.

@Giga Kokaia, @Rob Evans, @Aman - Thank you for the suggestions it became more easy to think.