Skip to content

Instantly share code, notes, and snippets.

@vutranvn
Last active October 8, 2017 20:21
Show Gist options
  • Save vutranvn/a00fc4c22ea95138e83440a0f5271f47 to your computer and use it in GitHub Desktop.
Save vutranvn/a00fc4c22ea95138e83440a0f5271f47 to your computer and use it in GitHub Desktop.
/**
* For Ubuntu 16.04
**/
- Update
> sudo apt-get update
- Install packages
> sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
- Add Docker’s official GPG key:
> curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- Verify
> sudo apt-key fingerprint 0EBFCD88
Output:
pub 4096R/0EBFCD88 2017-02-22
Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid Docker Release (CE deb) <docker@docker.com>
sub 4096R/F273FCD8 2017-02-22
- Setup stable repository
> sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
- Update
> sudo apt-get update
- Install
> sudo apt-get install docker-ce
- Check status
> sudo systemctl status docker
- Enable start auto system boot
> sudo systemctl enable docker
- Uninstall the Docker CE
> sudo apt-get purge docker-ce
> sudo rm -rf /var/lib/docker
- Non-root access
> sudo groupadd docker
> sudo usermod -aG docker $USER
- Access container (in sample above: ubuntu is container)
> docker run -it ubuntu bash
- Installing docker-compose: reference from: https://github.com/docker/compose/releases
- List all exited containers
> docker ps -aq -f status=exited
- Remove stopped containers
> docker ps -aq --no-trunc | xargs docker rm
- Remove dangling/untagged images
> docker images -q --filter dangling=true | xargs docker rmi
- Remove containers created after a specific container
> docker ps --since a1bz3768ez7g -q | xargs docker rm
- Remove containers created before a specific container
> docker ps --before a1bz3768ez7g -q | xargs docker rm
- Use --rm for docker build: Use --rm together with docker build to remove intermediary images during the build process
** Using basic **
> mkdir -p /home/website/html
> cd /home/website/html
> nano index.html
<html>
<head>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" integrity="sha256-MfvZlkHCEqatNoGiOXveE8FIwMzZg4W85qfrfIFBfYc= sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
<title>Hello,</title>
</head>
<body>
<div class="container">
<h1>Hello World,</h1>
<p>This nginx page!</p>
</div>
</body>
</html>
> sudo docker run --name my-server-name -p 80:80 -d -v /home/website/html:/usr/share/nginx/html nginx
- Access docker container
> docker exec -it container_name bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment