PoshJosh's Blog

Docker Titbits

November 13, 2019

Image Names

  • Docker container and image names should be alpha-numeric [A-Za-z_-].

The names are used to create files on the file system… some file systems don’t play well with non alpha-numeric characters in names.

Useful Commands

  • Host ip.

Host could be viewed by running the following command as root user:

C:\WINDOWS\system32>docker-machine ip default
192.168.99.100
  • List machines
C:\WINDOWS\system32>docker-machine ls
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER     ERRORS
default   *        virtualbox   Running   tcp://192.168.99.100:2376           v18.09.7
  • List processes
C:\WINDOWS\system32>docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                                              NAMES
52c60eacd03d        jenkinsci/blueocean   "/sbin/tini -- /usr/…"   About an hour ago   Up About an hour    0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp   jenkins-blueocean
  • SSH into a Container
    • Use docker ps to get the name of the existing container.
    • Use the command docker exec -it /bin/bash to get a bash shell in the container.
    • Generically, use docker exec -it to execute whatever command you specify in the container.
docker exec -u 0 -it <container_name_or_id> /bin/bash

Here, the -u 0 flag specifies that the root user with id 0 be used to run /bin/bash

Notes on docker build command

Docker builds images in layers.

FROM node:10-alpine

LABEL maintainer="https://github.com/poshjosh <posh.bc@gmail.com>"

RUN mkdir ./config && ls -a

RUN ls -a

CMD ["/bin/bash"]

At step 3 i.e (RUN mkdir ./config && ls -a) the output of ls -a will be:

.
..
config

At step 4 i.e (RUN ls -a) the output of ls -a will be:

.
..

Actual command and output

docker build -t posjosh/jelly-bean .
Step 1/5 : FROM node:10-alpine
 ---> d9f9ac153d4e
Step 2/5 : LABEL maintainer="https://github.com/poshjosh <posh.bc@gmail.com>"
 ---> Using cache
 ---> a4d5e3f83375
Step 3/5 : RUN mkdir ./config && ls -a
 ---> Running in 031276dbcdc3
.
..
config
Removing intermediate container 031276dbcdc3
 ---> 4d084c8280d8
Step 4/5 : RUN ls -a
 ---> Running in dfa696788d39
.
..
---> f8a989e7962b
Step 5/5 : ENTRYPOINT ["./docker-entrypoint.sh"]
---> Running in d159420d7aae
Removing intermediate container d159420d7aae
---> e117d69b8a7d
Successfully built e117d69b8a7d

Passing environment variables to docker run

$ docker run  --name <CONTAINER_NAME> -e JAVA_OPTS='-Xmx3g -Xms3g' <IMAGE_NAME>

Useful for Docker java

Remember java syntax for executing a jar file?

java <JAVA SYSTEM PROPERTY> -jar <path/to/my/jar> <COMMAND LINE ARGS>
java -Dserver.port=7788 -jar <path/to/my/jar> --server-port=7788

Use the following command to unpack all jar files in target folder of workspace directory to the current directory:

sh "find ${WORKSPACE}/target -type f -name '*.jar' -exec jar -xf {} ';'"

Don’ts

Avoid running containers with the --privileged flag as it gives all the capabilities to the container and also access to the host’s devices (everything that’s under the /dev folder).

If you run an image that does not come from a trusted source, be careful if it requires the --privileged flag. Of course, there are cases when this flag is needed, for instance when running containers on devices like Raspberry Pi. It is indeed used to access the GPIO interfaces and to be able to interact with the external world (and make an LED blink).


Written byChinomso IkwuagwuExcélsior

Limited conversations with distributed systems.

Modifying legacy applications using domain driven design (DDD)

Gherkin Best Practices

Code Review Best Practices

Hacking Cypress in 9 minutes

Some common mistakes when developing java web applications

How to make a Spring Boot application production ready

SQL JOINS - A Refresher

Add Elasticsearch to Spring Boot Application

Add entities/tables to an existing Jhipster based project

CSS 3 Media Queries - All over again

Maven Dependency Convergence - quick reference

Amazon SNS Quick Reference

AWS API Gateway Quick Reference

Amazon SQS Quick Reference

AWS API Gateway Quick Reference

AWS Lambda Quick Reference

Amazon DynamoDB - Quick Reference

Amazon Aurora

Amazon Relational Database Service

AWS Database Services

AWS Security Essentials

Amazon Virtual Private Cloud Connectivity Options

Summary of AWS Services

AWS Certified Solutions Architect - Quick Reference

AWS CloudFront FAQs - Curated

AWS VPC FAQs - Curated

AWS EC2 FAQs - Curated

AWS Achritect 5 - Architecting for Cost Optimization

AWS Achritect 4 - Architecting for Performance Efficiency

AWS Achritect - 6 - Passing the Certification Exam

AWS Achitect 3 - Architecting for Operational Excellence

AWS Achitect 2 - Architecting for Security

AWS Achitect 1 - Architecting for Reliability

Amazon DynamoDB Accelerator (DAX)

Questions and Answers - AWS Certified Cloud Architect Associate

Questions and Answers - AWS Certified Cloud Architect Associate

AWS Connectivity - PrivateLink, VPC-Peering, Transit-gateway and Direct-connect

AWS - VPC peering vs PrivateLink

Designing Low Latency Systems

AWS EFS vs FSx

AWS Regions, Availability Zones and Local Zones

AWS VPC Endpoints and VPC Endpoint Services (AWS Private Link)

AWS - IP Addresses

AWS Elastic Network Interfaces

AWS Titbits

Jenkins on AWS - Automation

Jenkins on AWS - Setup

Jenkins on AWS - Best practices

Introduction to CIDR Blocks

AWS Lamda - Limitations and Use Cases

AWS Certified Solutions Architect Associate - Part 10 - Services and design scenarios

AWS Certified Solutions Architect Associate - Part 9 - Databases

AWS Certified Solutions Architect Associate - Part - 8 Application deployment

AWS Certified Solutions Architect Associate - Part 7 - Autoscaling and virtual network services

AWS Certified Solutions Architect Associate - Part 6 - Identity and access management

AWS Certified Solutions Architect Associate - Part 5 - Compute services design

AWS Certified Solutions Architect Associate - Part 4 - Virtual Private Cloud

AWS Certified Solutions Architect Associate - Part 3 - Storage services

AWS Certified Solutions Architect Associate - Part 2 - Introduction to Security

AWS Certified Solutions Architect Associate - Part 1 - Key services relating to the Exam

AWS Certifications - Part 1 - Certified solutions architect associate

AWS Virtual Private Cloud (VPC) Examples

Curated info on AWS Virtual Private Cloud (VPC)

Notes on Amazon Web Services 8 - Command Line Interface (CLI)

Notes on Amazon Web Services 7 - Elastic Beanstalk

Notes on Amazon Web Services 6 - Developer, Media, Migration, Productivity, IoT and Gaming

Notes on Amazon Web Services 5 - Security, Identity and Compliance

Notes on Amazon Web Services 4 - Analytics and Machine Learning

Notes on Amazon Web Services 3 - Managment Tools, App Integration and Customer Engagement

Notes on Amazon Web Services 2 - Storages databases compute and content delivery

Notes on Amazon Web Services 1 - Introduction

AWS Auto Scaling - All you need to know

AWS Load Balancers - How they work and differences between them

AWS EC2 Instance Types - Curated

Amazon Web Services - Identity and Access Management Primer

Amazon Web Services - Create IAM User

Preparing Jenkins after Installation

Jenkins titbits, and then some

Docker Titbits

How to Add Chat Functionality to a Maven Java Web App

Packer - an introduction

Terraform - an introduction

Versioning REST Resources with Spring Data REST

Installing and running Jenkins in Docker

Automate deployment of Jenkins to AWS - Part 2 - Full automation - Single EC2 instance

Automate deployment of Jenkins to AWS - Part 1 - Semi automation - Single EC2 instance

Introduction to Jenkins

Software Engineers Reference - Dictionary, Encyclopedia or Wiki - For Software Engineers