Docker (software): Difference between revisions
Line 60: | Line 60: | ||
** To restrict listing to localhost use <code>-p 127.0.0.1:80:80</code> | ** To restrict listing to localhost use <code>-p 127.0.0.1:80:80</code> | ||
* <code>-it</code> to be interactive with a pseudo-tty | * <code>-it</code> to be interactive with a pseudo-tty | ||
==Networking== | |||
The default mode for networking is bridge. You should leave this for most of your containers. | |||
===bridge=== | |||
In bridge mode, the docker service acts as a NAT and gives each container a separate local IP along with the docker host. | |||
On linux, you can type <code>ip a</code> to see the ip address of the <code>docker0</code> network interface. | |||
On my server, it is <code>172.17.0.1/16</code>. | |||
To access services running on the host (such as MySQL or Postgres), you will need to make these services liston on this network interface and allow it through your firewall. | |||
Then make your docker containers connect using the ip address of your docker host. | |||
===host=== | |||
In this mode, docker processes have full access to your network. This can cause port conflicts if you are not careful. | |||
Furthermore, your docker service will have full access to your localhost. I do not recommend using this mode for most things. | |||
==Windows== | ==Windows== |
Revision as of 03:32, 25 September 2020
Installation
Ubuntu
# Uninstall old docker
sudo apt-get remove docker docker-engine docker.io containerd runc
# Update repos
sudo apt update
# Install prerequisites
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
# Add official gpg key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# Add docker repo
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
# Install
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
Windows
- Upgrade Windows to 2004 or newer
- Install and enable WSL2
- Install Docker Desktop
Guides
Usage
Images
Containers
docker container ls
Run
docker run <container>
-p hostport:containerport
to do port forwarding- To restrict listing to localhost use
-p 127.0.0.1:80:80
- To restrict listing to localhost use
-it
to be interactive with a pseudo-tty
Networking
The default mode for networking is bridge. You should leave this for most of your containers.
bridge
In bridge mode, the docker service acts as a NAT and gives each container a separate local IP along with the docker host.
On linux, you can type ip a
to see the ip address of the docker0
network interface.
On my server, it is 172.17.0.1/16
.
To access services running on the host (such as MySQL or Postgres), you will need to make these services liston on this network interface and allow it through your firewall.
Then make your docker containers connect using the ip address of your docker host.
host
In this mode, docker processes have full access to your network. This can cause port conflicts if you are not careful. Furthermore, your docker service will have full access to your localhost. I do not recommend using this mode for most things.
Windows
Notes on using docker with windows
Git bash paths
Reference
When mounting paths using git bash, you need to prepend a /
to $(pwd)
Resources
- freeCodeCamp.org Docker Tutorial for Beginners Video
- Scalable Microservices with Kubernetes Udacity Course
- I haven't watched this but it's by Google so it's probably good.
- Lessons 1-2 are on Docker and lessons 3-4 are on Kubernetes.