Wednesday, 17 January 2024

docker file env varialbe and docker file and image both specified

 https://vsupalov.com/docker-arg-env-variable-guide/

# no default value would crash
#ENV hey

# ENV needs a default value
ENV foo /bar
# you can also write
ENV foo=/bar
 https://vsupalov.com/docker-arg-env-variable-guide/
Docker image and build both specified 

If you add build: "." to a service that will build a Docker image out of the Dockerfile that exists in the directory when you build or up your compose file.

If you add image: "postgres:10.3-alpine" to a service that will pull down that image from the Docker Hub when you pull or up your compose file.

But what happens if you define both a build and image property like this:
web:
  build: "."
  image: "nickjj/myimage:1.0"

The world won’t explode, so that’s good.

When the image gets built, instead of using your COMPOSE_PROJECT_NAME or folder name + service name as the name of the image it will use what you have in the image property.

In the above example you would end up with an image named and tagged as nickjj/myimage:1.0 which will be built out of the Dockerfile in the current directory.

https://nickjanetakis.com/blog/docker-tip-57-using-build-and-image-in-the-same-docker-compose-service

No comments:

Post a Comment