Dockerfile: recipe to create image.
you can change the default name by using -f
docket image build -f some-dockerfile [old way:docker build]
inside file.
FROM command..shows the using distribuion.
minimal linux distro like debian.
ENV --for setting env variables.used for container building.
RUN --to run some commands.&& is for chaining the multiple commands.
if we redirect any log data to stdout/stderr, docker will handle the logging.
EXPOSE--to open any ports..mostly tcp and up(80 and 443).THis doesn't open directly, we need to use -p of docker command to use it.
WORKDIR -- to change workging dir.
COPY -- from local machine to containers.
docker image build -t customnginx .
docker container run -p 80:80 --rm nginx
docker image build -t nginx-with-html
docker container run -p 80:80 --rm nginx-with-html
. represents to build docker file in current directory.
Example: A node js app image.
In the dockerfile add below entries.I will use the base image as a nodejs official image.
FROM node:6-alpine
EXPOSE 3000
RUN apk add --update tini
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json package.json
RUN npm install && npm cache clean
#If we keep && it will execute second command only if first executes, if we use ; it won't check the first command success or not.
COPY . .
CMD ["tini","--","node","./bin/www"]
docker build -t testnode .
docker container run --rm -p 80:3000 testnode
docker images
docker tag testnode orgname/testing-node
docker push --help
docker push orgname/testing-node
docker image rm orgname/testing-node
docker container run --rm -p 80:3000 orgname/testing-node
you can change the default name by using -f
docket image build -f some-dockerfile [old way:docker build]
inside file.
FROM command..shows the using distribuion.
minimal linux distro like debian.
ENV --for setting env variables.used for container building.
RUN --to run some commands.&& is for chaining the multiple commands.
if we redirect any log data to stdout/stderr, docker will handle the logging.
EXPOSE--to open any ports..mostly tcp and up(80 and 443).THis doesn't open directly, we need to use -p of docker command to use it.
WORKDIR -- to change workging dir.
COPY -- from local machine to containers.
docker image build -t customnginx .
docker container run -p 80:80 --rm nginx
docker image build -t nginx-with-html
docker container run -p 80:80 --rm nginx-with-html
. represents to build docker file in current directory.
Example: A node js app image.
In the dockerfile add below entries.I will use the base image as a nodejs official image.
FROM node:6-alpine
EXPOSE 3000
RUN apk add --update tini
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json package.json
RUN npm install && npm cache clean
#If we keep && it will execute second command only if first executes, if we use ; it won't check the first command success or not.
COPY . .
CMD ["tini","--","node","./bin/www"]
docker build -t testnode .
docker container run --rm -p 80:3000 testnode
docker images
docker tag testnode orgname/testing-node
docker push --help
docker push orgname/testing-node
docker image rm orgname/testing-node
docker container run --rm -p 80:3000 orgname/testing-node
No comments:
Post a Comment