Home / Linux Admin /
(no brackets in commands unless specified)
Install Docker
curl -fsSL get.docker.com -o get-docker.sh && sh get-docker.shdocker pull [image-name]Create a container and run it in background
docker run -d --rm -p 8080:80 --name [createANameHere] --network [networkName] [image-name] [commandToRun]-d means detach and will run it in the background--rm will delete the container after it has stopped-p [containerPort]:[hostPort] connects the port on the host the port on the container NOTE this can (and DOES in the case of ufw) override firewall settings! only use for services you want exposed on the host's network! (use docker network for internal communication between containers) --network and its followup argument is optional, but recommended for production (more on networks below)Create a container and use it interactively
docker run -it --rm --name [createANameHere] [image-name] [commandToRun]
docker run -it --rm --name SwiftTest swift:5.7List containers
docker container ls -a-a lists all containers, not just those running currentlyConnect to existing, running container's main process
docker container attach [containerName]Run a new process in an existing, running container (best not to do in production)
docker -exec -it [containerName] [command (like /bin/bash)]Ctrl-p and then Ctrl-qCtrl keyCreate a network
docker network create --driver bridge [newNetworkName]--driver is optional as bridge is the default value
bridge - default - can communicate with others on same docker network as well as the internetoverlay - can communicate with other docker hosts - untestedbridge (not to be confused with the driver named bridge)list networks
docker network lsconnect existing container to a network
docker network connect [networkName] [containerName]docker network inspect [networkName]used to create docker images
a very basic dockerfile looks like this:
FROM [upstreamImageName]
MAINTAINER Your Name (email@address.com)
RUN [commandToRunDuringImageSetup]
COPY [local file or directory] [/path/to/a/conf/directory/in/image]
ENTRYPOINT ["command" , "arg1", "arg2", "..."] #brackets actually used here
CMD ["altPlaceForArg1", "altPlaceForArg2"] #brackets also here
EXPOSE [port exposed to host]
example:
FROM ubuntu:latest
MAINTAINER Your Name (email@address.com)
RUN apt update
RUN apt install nginx
COPY default.conf /etc/nginx/conf.d/
ENTRYPOINT ["/usr/sbin/nginx" , "-g", "daemon-off;"] #brackets actually used here
EXPOSE 80
build this image (while in the same directory:
docker build -t my-nginx-server:latest .-t means to tag the imagedocker run -d -p 80:80 --name webserver my-nginx-serverdeploys containers via yaml script
docker compose commandthis document last modified: November 18 2022 21:31
Home / Linux Admin /