Create and start the container as a detached process. The –rm option means to remove the container once it exits/stops. The -d flag means to start the container detached (in the background). Host network –network host, bind container port to host port.
docker run --rm -d --network host --name my_nginx nginx
Example docker file: https://github.com/yibo-cai/compass-db/raw/arm64/Dockerfile
We want to override the default entrypoint which starts mysql as CMD. First, start the image:
docker run --entrypoint /sbin/entrypoint.sh -it opnfv/compass-db
Not using attach b/c it allows only one tty, so:
docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 002af509471f opnfv/compass-db "/sbin/entrypoint.sh" 2 minutes ago Up 2 minutes 3306/tcp condescending_bartik docker exec -it -u root 002af509471f /bin/bash
sudo docker logs e537fb5d99f7
Note:
Remove everything
docker system prune docker container ls -a docker container rm cc3f2ff51cab cd20b396a061 docker rm -v $(docker ps -a -q -f status=exited) docker rmi $(docker images -f "dangling=true" -q) docker volume rm $(docker volume ls -qf dangling=true) docker-compose -f docker-compose.yml rm
Build (.) is context folder, can also be git url:
docker build -f path/to/Dockerfile .
Build and tag
docker build -t whenry/fedora-jboss:latest -t whenry/fedora-jboss:v2.1 .
cd dir/to/docker-compose.yml docker-compose up docker-compose down
.env and environment are two things
docker-compose –env-file ./config/.env.dev up
.env file format:
# MongoDB variables
MONGO_DB_PORT=27017
MONGO_DB_HOST_PORT=30017
MONGO_DB_VERSION=3.6
# Mosquitto
MOSQUITTO_USERNAME=mqtt --> OK
MOSQUITTO_PASSWORD='mqtt' --> '' included. everything after =
--> IGNORED
# Kura variables
ARTEMIS_PORT=1883
KURA_PORT=8080 # blah --> ERROR
$ cd /path/to/Dockerfile $ sudo docker build .
View running processes
$ sudo docker ps
View all processes
$ sudo docker ps -a
Run an image in a new container daemonized
$ sudo docker run -d <image_name>
Run an image in interactive mode with the command /bin/bash
$ sudo docker run -i -t <image_name> /bin/bash
Run an image in interactive mode with the command /bin/bash and link the ports.
$ sudo docker run -i -t --link <docker_container_name>:<docker_container_alias> <image_name> /bin/bash
Run an image with an ENTRYPOINT command in interactive mode with the command /bin/bash
$ sudo docker run --entrypoint /bin/bash -i -t <image_name>
Run an image in interactive mode with the command /bin/bash mounting the host director /var/app/current to the container directory /usr/src/app
$ sudo docker run -i -t -v /var/app/current:/usr/src/app/ <image_name> /bin/bash
Run an image in interactive mode with the command /bin/bash setting the environments variables FOO and BAR
$ sudo docker run -i -t -e FOO=foo -e BAR=bar <image_name> /bin/bash