Detailed modify Docker time zone and Docker common commands _docker

Source: Internet
Author: User
Tags time zones docker ps docker cp docker run

A few days ago encountered such a business scenario, the database runs in the Docker, the Docker city is UTC so it is 8 hours away from the Beijing time. However, you cannot rerun a container, only to ensure that the database is running, and to copy the host's time zone to the Docker container. Very distressed,

First I change the host's time zone to CST Beijing time. Then copy the host's time zone to the Docker container. Commands are as follows

Docker cp/etc/localtime: "Container ID or name"/etc/localtime

Of course, you can also enter the container to modify the time zone (but my container changes always report/etc/localtime file read-only, do not allow modification.) So I used the above method), the command is as follows

Add all the time zones first

And then modify the time zone

APK add tzdata 
ln-sf/usr/share/zoneinfo/asia/shanghai/etc/localtime 
echo "Asia/shanghai" >/etc/timezone

Of course, in the container to change, but also very troublesome, every time you start a new container to modify, so in the dockerfile to modify better. Commands are as follows

ENV Tz=asia/shanghai
RUN ln-snf/usr/share/zoneinfo/$TZ/etc/localtime && echo $TZ >/etc/timezone

Finally, attach Docker common commands

Docker PS View the running container

Docker ps-a View stopped containers

Docker ps-q list only container IDs

Docker Ps-s Displays the container size.

Docker Images view Mirrors

Docker images-q only list mirror IDs

Docker Images–tree lists all the submitted histories of mirrors in a tree structure.

Docker pull image_id Download IMAGE

Docker push image_id upload IMAGE

Docker RMI image_id Delete IMAGE

Docker Rmi-f forcibly removes the mirror, even if it is being used;

Docker Logs-f < container name orid> View Container log

Docker Start|stop|restart start, stop, and restart one or more specified containers.

Start a container and go into interactive mode

Docker Start-i Containerid

Displays the history of a mirror;

Docker History Image_name

Enter the container

Docker exec-it  container ID  bin/bash

Start the container and start Bash (interactive):

$docker run-i-T <image_name/continar_id>/bin/bash

Start the container to run later (more general way):

$docker run-d-it image_name

Docker Run Command explain

-D run the container in the background and return the container ID;

-I run the container in interactive mode, which is usually used with-t at the same time;

-T reassign a pseudo-input terminal to the container, usually used concurrently with-I;

Map the container port to the host's port

 
 

A container is fixed to a new image, followed by Repo:tag optional

 
 

Delete one or more container

 
 

Delete all the container

Docker RM ' Docker ps-a-Q '

Ditto, remove all container

Docker Ps-a-Q | Xargs Docker RM  

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.