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 command2 docker container run --rm alpine <command> <term>3 # working example4 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 nginx2docker container port nginx3docker 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 myAppNet2docker container run --name newNginx -d --network myAppNet nginx3docker 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>