How can you override a command that will be executed in a container of a specific service in Docker Compose?

Experience Level: Senior
Tags: Docker Compose

Answer

You can do this by modifying the entrypoint: property of your service.

version: "3.9"
services:
  my-service:
    image: busybox
    entrypoint: ["/bin/sh", "-c", "sleep 1d"]

Setting entrypoint both overrides any default entrypoint set on the service’s image with the ENTRYPOINT Dockerfile instruction, and clears out any default command on the image - meaning that if there’s a CMD instruction in the Dockerfile, it is ignored.

Comments

No Comments Yet.
Be the first to tell us what you think.
Docker Compose
Docker Compose

Are you learning Docker Compose ? Try our test we designed to help you progress faster.

Test yourself