hmushtaq avatar

Some useful Docker commands

hmushtaq

Published: 02 Jun 2018 › Updated: 02 Jun 2018Some useful Docker commands

Some useful Docker commands

Lately I've been using Docker quite often and loving it, as it makes it really simple to deploy applications. Today I will discuss some useful Docker commands that are handy.


image source

1. Docker exec

Let us say you are running a docker container in detached mode, you can still directly execute commands on it, using docker exec. For example, if you want to open a file using vim in docker for editing it, you can issue the following command.

docker exec -it container_name sh -c 'vi somedirinsidedocker/somefile.txt'

2. Docker container start

If for some reason you want to stop a container for a moment, you can restart it by using this command. For stopping a container you use docker stop container_name, while for restarting it, you would use docker container start container_name.

3. Docker inspect

You can use this command to get all the details about a container, such as its IP Address for example. The syntax is docker inspect container_name. If you want to see a specific attribute, you can use grep for filtering it out. For example, for knowing the IP address, we would use docker inspect container_name | grep IPAddress.

4. Docker cp

With this command, you can copy files/folders between host and the container. To copy from host to container, use docker cp file_or_folder_on_host container_name:destination_folder_on_container. To copy from container to host, use docker cp container_name:file_or_folder_on_container destination_folder_on_host.

5. Docker rename

This command renames a container. Example usage is docker rename old_name new_name.

For the full list of commands, you can visit https://docs.docker.com/engine/reference/commandline/docker/.

Leave Some useful Docker commands to:

Written by

A Programmer with a PhD degree

Read more #technology posts


Best Posts From hmushtaq

We have not curated any of hmushtaq's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From hmushtaq