• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

docker

Jekyll on Docker Container

August 30, 2022

Here’s how to run Jekyll in a Docker container.

mkdir blog
cd blog
docker run -v $(pwd):/site bretfisher/jekyll new .
docker run -p 4000:4000 -v $(pwd):/site bretfisher/jekyll-serve

mkdir blog cd blog docker run -v $(pwd):/site bretfisher/jekyll new . docker run -p 4000:4000 -v $(pwd):/site bretfisher/jekyll-serve

Another option is to use docker compose. Create a docker-compose.yml file.

version: 3.5
services:
  jekyll:
    image: bretfisher/jekyll-serve
    volumes:
      - .:/site
    ports:
      - '4000:4000'

version: 3.5 services: jekyll: image: bretfisher/jekyll-serve volumes: - .:/site ports: - '4000:4000'

Run Jekyll.

cd blog
docker-compose up -d

cd blog docker-compose up -d

Stop Jekyll.

cd blog
docker-compose down

cd blog docker-compose down

Filed Under: Linux Tagged With: container, docker, docker-compose, down, jekyll, up

Run MySQL in a Docker container

December 12, 2021

How to run MySQL commands in a Docker container.

#!/bin/bash
set -a; source <(cat .env | sed -e '/^#/d;/^\s*$/d' -e "s/'/'\\\''/g" -e "s/=\(.*\)/='\1'/g"); set +a
docker exec wp_db mysql -uroot -p${MYSQL_PASSWORD} -e " \
use db1; \
select * from wp_options where option_name='siteurl'; \
select * from wp_options where option_name='home';" 2>/dev/null

#!/bin/bash set -a; source <(cat .env | sed -e '/^#/d;/^\s*$/d' -e "s/'/'\\\''/g" -e "s/=\(.*\)/='\1'/g"); set +a docker exec wp_db mysql -uroot -p${MYSQL_PASSWORD} -e " \ use db1; \ select * from wp_options where option_name='siteurl'; \ select * from wp_options where option_name='home';" 2>/dev/null

  • The first command loads the content of .env to environment variables.
  • The MySQL password can then be used using the ${MYSQL_PASSWORD} variable.
  • I’m using sed to get around the special characters in the password.
  • The second command runs docker exec on wp_db container.
  • The last 3 commands are the actual sql commands.
  • We are selecting to use the db1 database.
  • Then we run select statements from the wp_options table.
  • Finally, 2>/dev/null suppresses errors and warning to null.

Filed Under: Cloud, Linux Tagged With: database, docker, environment, exec, mysql, password, select, tables

Rebuild Docker containers

December 12, 2021

How to rebuild your application from scratch using Docker.

#!/bin/bash
docker-compose down -v
docker rmi $(docker images -a -q)
docker-compose up -d
docker-compose restart -t 10

#!/bin/bash docker-compose down -v docker rmi $(docker images -a -q) docker-compose up -d docker-compose restart -t 10

Steps

  • Purge the containers.
  • Delete docker images.
  • Reinitiate docker.
  • Restart docker.

Filed Under: Cloud, Linux Tagged With: application, containers, docker, docker-compose, down, rebuild, remove, restart, up

Install Docker on Amazon Linux 2

December 11, 2021

Steps how to install Docker and Docker Compose on Amazon Linux 2.

Install Docker

$ sudo amazon-linux-extras install docker
$ sudo service docker start
$ sudo usermod -a -G docker ec2-user

$ sudo amazon-linux-extras install docker $ sudo service docker start $ sudo usermod -a -G docker ec2-user

Start at boot.

$ sudo chkconfig docker on

$ sudo chkconfig docker on

Install git (optional).

$ sudo yum install -y git

$ sudo yum install -y git

Install Docker Compose

$ sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) \
-o /usr/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose

$ sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) \ -o /usr/bin/docker-compose $ sudo chmod +x /usr/local/bin/docker-compose

Check

docker --version
docker-compose --version

docker --version docker-compose --version

Filed Under: Linux Tagged With: amazon, docker, docker-compose, git, install

Stop and remove all Docker containers

December 11, 2021

How to stop and remove all Docker containers.

Stop all containers

$ docker kill $(docker ps -q)

$ docker kill $(docker ps -q)

Remove all containers

$ docker rm $(docker ps -a -q)

$ docker rm $(docker ps -a -q)

Delete all docker images

$ docker rmi $(docker images -q)

$ docker rmi $(docker images -q)

Filed Under: Linux Tagged With: containers, delete, docker, images, remove, stop

Docker container logs

December 10, 2021

How to check Docker container logs. Look for the container ID.

$ docker ps -a
3e2c1193915f

$ docker ps -a 3e2c1193915f

To view the logs for the container.

docker logs 3e2c1193915f
# or
docker container logs 3e2c1193915f

docker logs 3e2c1193915f # or docker container logs 3e2c1193915f

Filed Under: Linux Tagged With: container, docker, logs, view

Docker ps

December 9, 2021

Check Docker running processes.

$ docker ps -a

$ docker ps -a

To see it in real time.

$ watch docker ps

$ watch docker ps

Filed Under: Linux Tagged With: docker, process, ps, real-time, watch

Rocky Linux in a Container

November 7, 2021

Here’s how to run Rocky Linux in a Docker container.

Download the image.

docker pull rockylinux/rockylinux

docker pull rockylinux/rockylinux

Create a Rocky Linux container called bullwinkle.

docker run -it --name bullwinkle -d rockylinux/rockylinux

docker run -it --name bullwinkle -d rockylinux/rockylinux

Login to the container using bash.

docker exec -it --user root bullwinkle /bin/bash

docker exec -it --user root bullwinkle /bin/bash

When done, stop and delete the container.

docker ps -a
docker stop container_ID
docker rm container_ID

docker ps -a docker stop container_ID docker rm container_ID

Filed Under: Linux Tagged With: bash, container, docker, linux, pull, rocky

  • Go to page 1
  • Go to page 2
  • Go to page 3
  • Go to page 4
  • Go to Next Page »
  • Home
  • About
  • Archives

Copyright © 2023