Code Monkey home page Code Monkey logo

dockers's Introduction

dockers

docker projects and notes

Various Commands in Dockerfile

1] FROM - used to define the base image, on which we will be building

FROM <image-tag> usually the 1st line of a Dockerfile

Example: FROM ubuntu:18.04 OR FROM python:latest

2] ADD - used to add files to the container being build

ADD <source> <destination in container>

Example: ADD . /var/www/html

3] RUN - used to add layers to the base image,by installing components.Each RUN statement,adds a new layer to the docker image

RUN <command to install pkgs>

Example: RUN apt-get update OR RUN apt-get -y install apache2

4] CMD - used to run commands on the start of the container.These commands run only when there is no argument specified while running the container.CMD command gets skipped if argument is specified while running the docker.

CMD <cmd>

Example: CMD apachectl -D FOREGROUND

5] ENTRYPOINT - used strictly run commands the moment the container initializes.The difference between CMD and ENTRYPOINT will run irrespective of the fact whether argument is specified or not.

ENTRYPOINT <cmd>

Example: ENTRYPOINT apachectl -D FOREGROUND

6] ENV - used to define environment variables in the container run-time.

ENV <name> <value>

Example: ENV name superman

7] WORKDIR

8] COPY

Dockerfile Example to install and run Apache2

ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get -y update
RUN apt-get -y install apache2
ADD . /var/www/html
ENTRYPOINT apachectl -D FOREGROUND
ENV name superman

Run docker without sudo

sudo usermod -aG docker $USER

Build docker image from Dockerfile

sudo docker build . -t <image-tag>

sudo docker build - < Dockerfile

Run docker

sudo docker run -it -d -p <host-port>:<container-port> <image-tag>

Access container shell

sudo docker exec -it <container-Id> bash

dockers's People

Contributors

viinay avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.