Navigate back to the homepage

learning docker - day 1

Christos Paschalidis
December 14th, 2020 · 1 min read

Commands to access and execute commands inside containers

connect to ubuntu as host in the box (not in the os). As an interactive shell

spins a new container also this will stop the container running when you exit

1docker container run -it --name ubuntu ubuntu

connect back into a docker box and user bash

spins a new container also this will stop the container running when you exit

1docker container start -ai ubuntu

execute a command and delete container after execution

spins a new container also this will stop and delete the container running when you exit

1# pseudo command
2 docker container run --rm alpine <command> <term>
3 # working example
4 docker container run --rm alpine nslookup search

see the shell inside a running container

you need to have an image called mysql for this also this will keep the container running when you exit also works only when you have an existin container running

1docker container exec -it mysql bash

get into an alpine image (because there is not bash in alpine)

1docker container -it alpine sh

Docker network generals and its commands

expose a port to your host from the running image

1docker container run -p

see all the ports on this container

1docker container port <container>

see the traffic in ngix

1docker container run -p 80:80 --name nginx -d nginx
2docker container port nginx
3docker container inspect --format '{{ .NetworkSettings.IPAddress }}' nginx

my ip address

1ifconfig en0

Docker network useful commands

list networks

1docker network ls

inspect

1docker network inspect

create

1docker network create --driver

attach a network to a container

1docker network connect

detach a network to a container

1docker network disconnect

create image with nw

1docker network create myAppNet
2docker container run --name newNginx -d --network myAppNet nginx
3docker network inspect myAppNet

connect a container to an existing network

will add the container ID to another network. in the end the container will belong to two nets

1docker network connect <netIP> <containerID>

More articles from blog for tech

Generate a Github webhook token

what I learned today

November 12th, 2020 · 1 min read

learning docker - day 6

Swarm lifecycle

January 3rd, 2021 · 1 min read
© 2020–2021 blog for tech
Link to $https://github.com/paschalidiLink to $https://www.linkedin.com/in/christos-paschalidis/