Skip to main content

Docker basic commands (podman)

  Docker basic commands. Also use full for podman.

  •   docker search <image-name> - search for image in docker-hub 
  • docker run <options> <image-name> - by default docker will run command foreground. For running background use -d option, -it interact with the container instead of just seeing the output, --name option for giving friendly name when lunching container
  • docker logs <friendly-name|container-id> - container standard err or standard out messages 
  • docker inspect <friendly-name|container-id> - more detailed information about running container
  • docker ps - list all running docker containers 
  • docker run -p <host-port>:<container-port> - define ports you want to bind, when running conatiner
  • docker port <friendly-name|container-id> - list port mappings or a specific port mapping for container 
  • -v <host-dir>:<container-dir> - mounts container-dir to host-dir
  • docker stop <friendly-name|container-id> - stopping running containerdocker stop <friendly-name|container-id> - stopping running container
  • docker images & docker image ls - list pulled images 
  • docker image rm 'container id' - remove docker image 

#docker run -it -d --rm --name linux1 ubuntu /bin/bash
CONTAINER ID   IMAGE     COMMAND       CREATED              STATUS              PORTS     NAMES
370804e50947   ubuntu    "/bin/bash"   About a minute ago   Up About a minute             linux1

-d - detach from container asap it started
--rm - removes a container after stopping
--name - container friendly name

Shared Host File System (Volume Mounting)
docker run --rm -v ${PWD}:/myvol ubuntu /bin/bash -c "ls -lha > /myvol/myfiles.txt"
-v - volume Mounting  local:remote

docker run -it --rm --name my-running-script php:7.2-cli /bin/bash

docker run -it --rm -v ${PWD}:/myfiles -w /myfiles --name my-running-script php:7.2-cli /bin/bash
-w - working dir

Port forwarding
docker run -d -p 8080:80 -v ${PWD}:/var/www/html  php:7.2-apache
-p - port forwarding

docker inspect cont_id
docker logs cont_id
docker image ls
docker ps

Run container from dockerfile
docker build -t myphpapp:web .
docker run -p 8000:8000 myphpapp:web
-t - tagging image

Copy from docker to local:

docker container ls
docker cp contained_id:/(file location) (location on host)

Dockerfile example:

FROM ubuntu
RUN mkdir /myproject
RUN apt update -y
COPY index.php /myproject
WORKDIR /myproject
#CMD ["php", "-S", ""]


Popular posts from this blog

Salt -- cheat sheet

      The Salt system is a Python-based open-source remote execution framework for configuration management, automation, provisioning and orchestration.  A basic Salt implementation consists of a Salt master managing one or more Salt minions.

Cheat Sheet

Bash: echo $? - exit status of last command (0 no error) ' - Single quote removes meaning special meaning of special character. find /qwe -type f -iname *.js -exec cp --parents -t /tmp/ {} + -- find all js files and copy with parent directory ystemctl set-default (ls -l /lib/systemd/system/runlevel*) -- set runlevel echo <password> | sudo -S for i in t@01 st@02 ba@sta03;do ssh -o RequestTTY=true $i "sudo -l";done -- allow tty present VIM: :r! sed -n '16,812 p' < input_file.txt -- copy line range from input_file :1,10d -- delete line from 1 to 10 :se nu -- show line numbers Apache: Redirection in Apache (By default, the Redirect directive establishes a 302, or temporary, redirect.): URL: <VirtualHost *:80> ServerName Redirect 301 /oldlocation </VirtualHo

Euro trip. Chapter1: Bucovice-Prague-Nuremberg-Leipzig-Dresden

    Begin to write something every time is complicated for me. Any way i should start. So this trip was somehow unplanned. Where to go, stay ... everything planned on way.    Trip started 2nd of July from Bucovice to Prague. Made reservation on "Hotel Globus" for one night. After check-inn we went to centre walk, see landmarks  of Prague. Additional we have a lunch at asian cafe.     3rd July. Next our plan was drove from Prague to Munich stay one night in camp hostel, visit Munich Zoo. But plans changed on way and we decided drove first Nuremberg to see my friend. Made reservation at "Azimut Hotel". As we arrived earlier check-inn was after 3PM, parked car and we decided not to waste time go and see Nuremberg. We have a lunch some soup and german sausage. And also for 30 euros we took city tour by bus about 2 hour. We saw almost whole city with information (recommended). Evening we meet my friend have a lunch thanks special thanks Fagani. Before driving to Leipzig