Docker/Basics

From r00tedvw.com wiki
Revision as of 14:58, 20 June 2018 by R00t (Talk | contribs)

Jump to: navigation, search

Docker Basics

Contents

Installation

The Docker Way

Installation done on CentOS7. Install, start, enable for system startup.

~$ sudo yum check-update
~$ curl -fsSL https://get.docker.com/ | sh
~$ sudo systemctl start docker
~$ sudo systemctl enable docker

Using a repo

NOTE: Untested.

~$ sudo vim /etc/yum.repos.d/docker.repo
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/

Find and install from Repo

~$ sudo yum search docker-ce
~$ sudo yum install -y docker-ce
~$ sudo systemctl start docker
~$ sudo systemctl enable docker

Images

search

public Docker Hub (repo) for images of software builds. Includes both official (owner) created and public (consumer) created so be careful with what you download for obvious security reasons.

~$ sudo docker search software_name

pull

download docker images for local deployment.

~$ sudo docker pull repository/software_name:tag

list

get a listing of local available docker images

~$ sudo docker images

delete image

delete a local docker image

~$ sudo docker rmi image_id

history

see a history of the docker image. It is important to know that the history only stacks based on the image_id the container was started up from. If you create multiple changes and commit them separately, the latest image will have all the updates, but will not the multiple comments if they were included in the commit. If you want a consistent linear growth of commit history in the image, you must start the container with the latest image_id before making updates.

~$ sudo docker history image_id

commit

create a new image based on the specified container. It is important to note that if you want to maintain a consistent linear growth of commit history in the image, you must start the container with the latest image_id before making updates or commits.
Also, as best practice it is recommended that you specify the repository where the docker image will be pushed to (whether public or private). Locally however, the repository name structure can be anything, but you should follow best practice to keep organized.

~$ sudo docker commit -m "comment" -a "Author" container_id repository/image_name:tag
ie. ~$ sudo docker commit -m "installed telnet" -a "root" ce056f9a7d2f root_repo/centos-updated:version3

Containers

run

There are a few different options to consider when running a container.

interactive -it
add the -it option if you want to be interactive with the container, ie. immediately log in as root and have a shell.
~$ sudo docker run -it image_id
standard
no switches. This will run the container and execute the default command. In basic instances it would be "/bin/bash" which is an unattached shell that would immediate exit causing the container to stop running.
~$ sudo docker run image_id
name with meaningful name --name=meaningful_name
add a meaningful name instead of allowing docker to randomly create one.
~$ sudo docker run --name=meaningful_name image_id
hostname --hostname=value
specify a specific hostname for the container rather than allowing a random one to be generated.
~$ sudo docker run --hostname=defined_hostname image_id
automatically delete containers upon exit --rm
a great time saving option that prevents you from having lots of stopped containers lingering.
~$ sudo docker run --rm image_id

list

There are a couple of different main options to consider when listing containers.

standard
no switches. This will list all the currently running containers.
~$ sudo docker container ls
all containers -a
add the -a switch if you want to see all containers including those that are not running.
~$ sudo docker container ls -a

remove

remove a container

~$ sudo docker rm container_id

Docker Hub

Docker Hub allows you to store your images either in private or public repositories. Personal accounts get (1) free private repo, Organizations do not get any free private repos. Both can purchase private repos at any time through a subscription model.

login

login to the docker hub.

~$ sudo docker login -u username

pull

download docker images for local deployment.

~$ sudo docker pull repository/software_name:tag

push

push a new or updated docker image.

~$ sudo docker push repository/software_name:tag

logout

~$ sudo docker logout
Personal tools
Namespaces

Variants
Actions
Navigation
Mediawiki
Confluence
DevOps Tools
Ubuntu
Ubuntu 22
Mac OSX
Oracle Linux
AWS
Windows
OpenVPN
Grafana
InfluxDB2
TrueNas
OwnCloud
Pivotal
osTicket
OTRS
phpBB
WordPress
VmWare ESXI 5.1
Crypto currencies
HTML
CSS
Python
Java Script
PHP
Raspberry Pi
Canvas LMS
Kaltura Media Server
Plex Media Server
MetaSploit
Zoneminder
ShinobiCE
Photoshop CS2
Fortinet
Uploaded
Certifications
General Info
Games
Meal Plans
NC Statutes
2020 Election
Volkswagen
Covid
NCDMV
Toolbox