[docker] Basic command

June Chung
2 min readAug 2, 2020

docker ps
-> viewing running containers

docker image ls
-> viewing images that have been built/pulled

(1) Can do everything locally — create docker file & build & deploy
(2) Can pull existing images from docker hub

  1. Create the docker file

If you create a lot of RUN commands — it is inefficient. (creates additional layers in the image)

2. Build the docker file (=create an image)
- Go into the directory with docker file
- docker build .
- docker build -t my_first_image .

  • docker image ls
    -> should be able to see the image
  • Docker COMMIT command (easy way)
    → inside docker container, you download stuff and then you can commit the container as it is to be an image
    docker commit <containerID> 1junechung/newcustomimage

3. Run the Image!
(Option) can push to docker hub for further usage
OR can run from local repository directly (image ls)
Interactively running docker images :
docker run -it <image_name> --name <container> /bin/sh(entrypoint)
entrypoint can be /bin/bash etc — or else conainer will exit right away
can do -d or -p 8080:8080 to add more commands

docker run --name container1 my_first_image(actual image name) If docker has permission issues (only root allowed and normal user is not allowed)sudo usermod -aG docker $(whoami)If this doesn't work as well -> 
It means no privilege for creating new sockets in docker
sudo chmod 666 /var/run/docker.sock

4. How to build a new customized docker image

Create Docker file (maybe based on an existing image)

And then build the image first (go to directory which has Dockerfile)
docker build .

Then tag the image to push to container registry
Grab the image ID : random letters
docker tag <imageID> 1junechung/nodewithgit(name the image)

Then push image to docker hub
docker login
docker push 1junechung/nodewithgit(name of image)

ECR basic commands

How to use ECR
1. Login to AWS ECR registry first (= same as docker login)
aws ecr get-login-password --region ap-southeast-1 | docker login --username AWS --password-stdin 925878512292.dkr.ecr.ap-southeast-1.amazonaws.com
NO need to fill in username or password — just the command itself

2. Build your docker image

--

--