简体   繁体   中英

Is Dockerfile replacable with docker-compose.yaml?

I'd like to build and operate containers only with docker-compose. Is it possible to do it with using all features of the Dockerfile, but without using it?

IMHO not, but I'm not sure if it is true. For example: are there any replacement of Dockerfile's RUN,ADD,COPY commands in the docker-compose.yaml? I can't find.

In general, no: the Dockerfile says how to build an image, and the docker-compose.yml says how to run it. There are various combinations of things that it's impossible to do in one place or the other.

In some cases you can simulate things the Dockerfile might do with docker-compose.yml directives (you can use volumes: to mount content into a running container, which looks similar to COPY ing the content into an image) but they're not the same and you generally can't use exclusively one, unless you can describe your application using only prebuilt images.

I'd tend to recommend the Dockerfile COPY and CMD directives over trying to use only the docker-compose.yml equivalents. Environment variables are often runtime configuration ("what is the host name of the database server?") and those it makes more sense to specify in the docker-compose.yml or other runtime configuration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM