Skip to content

Instantly share code, notes, and snippets.

@c02y
Last active May 4, 2021 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c02y/20038ef2f1f31198b733a5e16c8d8b12 to your computer and use it in GitHub Desktop.
Save c02y/20038ef2f1f31198b733a5e16c8d8b12 to your computer and use it in GitHub Desktop.
Docker guide
  • Docker ** Prepare docker *** install docker package *** start and enable service
    • sudo systemctl start docker.service
    • sudo systemctl enable docker.service ** add permission and group
    • sudo usermod -aG docker $USER ** reboot your computer ** check if docker works
    • docker --version
    • sudo systemctl status docker.service ** get Ubuntu 16 base image
    • (docker search ubuntu to search image, goto https://hub.docker.com/ search the image and the right tag
    • docker pull ubuntu:xenial ** create your Ubuntu container with share folder
    • docker run -it -v ~/Public/tig:/Public/tig --net host --name Ubuntu16.04LTS ubuntu:xenial /bin/bash
      • -it -> interactive, not background
      • -v -> share folder
      • --net host -> using host network, proxy, don't forget to install proxychains4 and its cofig
      • --name -> new name
      • /bin/bash --> start command
    • install the necessary packages ** add a non-root user following the link: https://www.cyberciti.biz/faq/create-a-user-account-on-ubuntu-linux/
    • useradd -s /bin/bash -d /home/new-user -m -G sudo new-user
    • passwd new-user ** commit the current container into a new image
    • docker commit <container-ID> <new-image-name> ** start the container which starts with non-root user and workding dir
    • docker run -it -v ~/Public/tig:/Public/tig --net host --user <non-root-user-name> -w /home/new-user <new-image-name> /bin/bash
    • NOTE: shared folder and net don't share between containers, you have to manually define them when creating new container based on a new image which is commited from a old container which contains the shared foler and net ** start the created container after exiting it
    • docker ps -a to list all the containers
    • docker start -i $ID to start the specific container(ID is in docker ps -a) ** Misc docker commands
    • docker container rm $ID to remove the unneeded container
    • docker image ls -- check the size of the container
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment