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

Reset root pass in ESXi 5.5

    In this post i will show how to reset root password in ESXi 5.5. For this first we need any bootable linux distributor. In my example i used Ubuntu 16.04.     Boot from Ubuntu disk. Select try Ubuntu, wait for loading. After full loading open Terminal. Type fdisk -l for list all partitions hypervisor/system image is located on the first 250 MB partition (/dev/sda5) which contains the state.tgz file. Mount /dev/sda5 to /mnt sudo -s mount /dev/sda5 /mnt. Go to the /mnt cd /mnt . Copy state.tgz to /tmp folder cp state.tgz /tmp , cd /tmp. Unarchive state.tgz tar xzf state.tgz then   tar xzf local.tgz Go to the /etc directory in /tmp folder  cd etc/ . For deleting resetting password open shadow file with nano shadow  delete the password hash of ESXi root account. Close nano editor. Re add etc/ folder to local.tgz : tar czf local.tgz etc after it readd local.tgz to state.tgz: tar czf state.tgz local.tgz . Copy state.tgz mnt/ folder: cp state.tgz /mnt/ . umount /mnt 

Service Hosting - KVM documentation

Host System Requirements: Minimum host system requirements 6 GB free disk space. 2 GB RAM. Recommended system requirements One core or thread for each virtualized CPU and one for the host. 2 GB of RAM, plus additional RAM for virtual machines. 6 GB disk space for the host, plus the required disk space for the virtual machine(s). KVM Hypervisor Requirements: an Intel processor with the Intel VT-x and Intel 64 virtualization extensions for x86-based systems; or an AMD processor with the AMD-V and the AMD64 virtualization extensions. Installing the Virtualization Packages: To use virtualization on OL7, at minimum, you need to install the following packages: # yum install qemu-kvm libvirt qemu-kvm: This package provides the user-level KVM emulator and facilitates communication between hosts and guest virtual machines. qemu-img: This package provides disk management for guest virtual machines. The qemu-img package is installed as a dependency of the qemu-kvm package. libvirt: