GithubHelp home page GithubHelp logo

docker_commands's Introduction

Docker Commands

  • How to create a DockerFile
  • Push Docker to DockerHub;
  • Pull Docker from DockerHub;
  • Examples.

How to create a DockerFile

Docker have many Tags to use and each one is a specific type.

FROM

The base image for building a new image. This command must be on top of the dockerfile.

MAINTAINER

Optional, it contains the name of the maintainer of the image.

RUN

Used to execute a command during the build process of the docker image.

ADD

Copy a file from the host machine to the new docker image. There is an option to use an URL for the file, docker will then download that file to the destination directory.

ENV

Define an environment variable.

CMD

Used for executing commands when we build a new container from the docker image.

ENTRYPOINT

Define the default command that will be executed when the container is running.

WORKDIR

This is directive for CMD command to be executed.

USER

Set the user or UID for the container created with the image.

VOLUME

Enable access/linked directory between the container and the host machine.

Now let's stat to create our first dockerfile with dotnetcore and chrome.

Example: Here we are using a dotnecore2.2 base image, and installing chrome(lastest version) also setting our work directory.

FROM mcr.microsoft.com/dotnet/core/sdk:2.2

RUN apt-get update && apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg \
hicolor-icon-theme \
libcanberra-gtk* \
libgl1-mesa-dri \
libgl1-mesa-glx \
libpango1.0-0 \
libpulse0 \
libv4l-0 \
fonts-symbola \
--no-install-recommends \
&& curl -sSL https://dl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list \
&& apt-get update && apt-get install -y \
google-chrome-stable \
--no-install-recommends \
&& apt-get purge --auto-remove -y curl \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /usr/src/app

Push Docker to DockerHub

Lets build a Dockerfile, please open a folder where is ur dockerfile and: containerName inst a "dockerfile", is the new name ex: dotnetcore

docker build -t containerName .

Now we have a Dockerfile lets Push then to DockerHub! First we need to give a tag name.

Lets check docker images inside my computer

docker images

Take a ID from "docker images" and give a tag

docker tag ID usuario_from_dockerHub/reponame:tagname(ex: 1.0)

Example: docker tag 949494949 sayoan/dotnetcore_22_chrome:1.0

Push a image to dockerhub

docker push usuario/reponame:tagname

Pull Docker from DockerHub

docker pull sayoan/dotnetcore_22_chrome:1.0

Check the docker IMAGE ID

docker images

Now lets run the container

docker run -t -i IMAGE_ID /bin/bash

We are inside container \o/

Examples

  • Important

We have N images and N containers, to see every image the container can take on:

docker images -a

Each image can be in more than one container. To see containers that are running:

docker ps -a

To kill each container:

docker kill ID

Open running container:

docker exec -it [container-id] bash

Caution!

stop all containers:

docker kill $(docker ps -q)

remove all containers

docker rm $(docker ps -a -q)

remove all docker images

docker rmi $(docker images -q)

exit from container

exit

download if dont exist image(if exist, only run) and run

docker container run IMAGE_ID

open again the container

docker start -a -i CONTAINER_ID

docker_commands's People

Contributors

sayoan avatar

Watchers

James Cloos avatar Saymon Oliveira avatar  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.