Unix Container
Jump to navigation
Jump to search
Container Howto
Web Site
Docker [docker.com]
Containers at Docker Store [store.docker.com]
Install and run a container
docker run -i -t ubuntu:18:04 /bin/bash
Create an image from a container Commit
- "b5673dbced61" is an image id
docker commit -m "Ubuntu 14.10 Demonstrator" -a "Author Name" b5673dbced61 demo:14.10
List Images (Source to initiare a containers)
docker images
Remove an image "b5673dbced61" is an image id
docker rmi b5673dbced61
Create a volume
docker volume create --name node_red_user_data
List volumes
docker volume ls
List containers (Running Virtual Machines)
- Running:
docker ps
- Full List
docker ps -a
Start and Stop a container
- Stop
docker stop "containerId or Name"
- Start (Batch)
docker start "containerId or Name"
- Start (and login in)
docker start -i "containerId or Name"
Update a restart option
- no
- on-failure
- unless-stopped
- always
docker update --restart=on-failure <container>
"Relogin" (Attach) into a Container
- "Relogin into a running container
docker attach "container Name"
Save an image
- "asw20/mailserver" is the image tag
docker save asw20/mailserver:latest -o mailserver.tar
Save all images
docker save $(docker images | sed '1d' | awk '{print $1 ":" $2 }') -o dockerimages.tar
Restore image
docker load -i dockerimages.tar
Remove a container
- "d0955f21bf24" is a container Id
docker rm d0955f21bf24
Remove all containers
docker stop $(docker ps -a -q) docker rm $(docker ps -a -q)
More Advence Topics
Build an image from a Dockerfile
docker build -t objectif/appname -f pathtoDockerfile
docker build -t [username]/docker-desktop git://github.com/rogaha/docker-desktop.git
Execute more advances
docker run -i -t --net="bridge" --name Demo -v /opt/docker/data mindesktop:v01.01
Dockerfile Sample
node Js app
- Create a new directory
Create node app
- Create package.json
{ "name": "docker_web_app", "version": "1.0.0", "description": "Node.js on Docker", "author": "First Last <first.last@example.com>", "main": "server.js", "scripts": { "start": "node server.js" }, "dependencies": { "express": "^4.16.1" } }
- Create server.js
'use strict'; const express = require('express'); // Constants const PORT = 8080; const HOST = '0.0.0.0'; // App const app = express(); app.get('/', (req, res) => { res.send('Hello world\n'); }); app.listen(PORT, HOST); console.log(`Running on http://${HOST}:${PORT}`);
Create Dockerfile
- Create a file Dockerfile
FROM node:10 # Create app directory WORKDIR /usr/src/app # Install app dependencies # A wildcard is used to ensure both package.json AND package-lock.json are copied # where available (npm@5+) COPY package*.json ./ RUN npm install # If you are building your code for production # RUN npm ci --only=production # Bundle app source COPY . . EXPOSE 8080 CMD [ "node", "server.js" ]
- Create a file .dockerignore
node_modules npm-debug.log
Build Image
- Don't forget the "." at the end...
docker build -t <username>/<applicationname> .
List Images
docker images
Run Image
docker run <username>/<applicationname>
Ghost (Blog Server)
FROM komljen/nodejs MAINTAINER Alen Komljen <alen.komljen@live.com> ENV GHOST_VERSION 0.5.7 ENV APP_ROOT /data/app RUN \ curl -sLO http://ghost.org/archives/ghost-${GHOST_VERSION}.zip && \ mkdir -p ${APP_ROOT} && \ unzip -uo ghost-${GHOST_VERSION}.zip -d ${APP_ROOT} && \ rm ghost-${GHOST_VERSION}.zip RUN \ cd ${APP_ROOT} && \ npm install --production ADD start.sh start.sh VOLUME ["$APP_ROOT"] RUN rm /usr/sbin/policy-rc.d CMD ["/start.sh"] EXPOSE 2368
Gui management solution for Docker
Portainer
Web site https://portainer.io
Dashboard access http://localhost:9000/#/dashboard
Deployment
docker run -d --name myPortainer -p 9000:9000 --restart always -v /var/run/docker.sock:/var/run/docker.sock -v /opt/portainer:/data portainer/portainer-ce
Upgrade
- Stop Portainer
- Remove Portainer
- Pull new /upgraded image
- Recreate Portainer
docker stop myPortainer docker rm myPortainer docker pull portainer/portainer-ce docker run -d --name myPortainer -p 9000:9000 --restart always -v /var/run/docker.sock:/var/run/docker.sock -v /opt/portainer:/data portainer/portainer-ce
Docker Server Remote Management
- These commands get run inside of your VM.
# Create the directory to store the configuration file. sudo mkdir -p /etc/systemd/system/docker.service.d
- Create a new file to store the daemon options.
sudo nano /etc/systemd/system/docker.service.d/options.conf
- Now make it look like this and save the file when you're done:
[Service] ExecStart= ExecStart=/usr/bin/dockerd -H unix:// -H tcp://0.0.0.0:2375
- Reload the systemd daemon.
sudo systemctl daemon-reload
- Restart Docker.
sudo systemctl restart docker