Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

297
Visualizações
dockerfile: how use CMD or ENTRYPOINT from base image

I have several base docker images which are not owned by me (so I cannot modify them). However, I'm creating new images from them with additional things installed.

What I can't figure out is how to tell dockerfile to copy the CMD (or ENTRYPOINT) of the base image. Something like this:

FROM other:latest
RUN my-extra-install
CMD <use-the-CMD-from-base-image>

I don't think there's any direct syntax for the CMD command to do what I want. I'm wondering if there's a workaround.

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

If you left it blank in your new Dockerfile, it will inherit the one from the base image.

For example:

base

FROM ubuntu
CMD ["echo", "AAA"]

layer1

FROM base

If you build above images and run layer1 you will get the following:

$ sudo docker run -it layer1
AAA
about 4 years ago · Santiago Trujillo Relatório

0

@Vor is right. But in case

# Dockerfile
FROM nginx:stable-alpine
ENTRYPOINT ["/docker-entrypoint.sh"]
COPY ./docker-entrypoint.sh /

and

# docker-entrypoint.sh
#!/usr/bin/env sh
set -e
exec "$@"

the default CMD from nginx:stable-alpine won't be executed in exec "$@".

You must to write default nginx-alpine's CMD by yourself(!) in Dockerfile

# Dockerfile
FROM nginx:stable-alpine
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["nginx", "-g", "daemon off;"]
COPY ./docker-entrypoint.sh /

OR change your docker-entrypoint.sh

# docker-entrypoint.sh
#!/usr/bin/env sh
set -e
exec nginx -g "daemon off;"

Hope it helps

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda