joppot

コピペで絶対動く。説明を妥協しない

プログラミング

I created docker shortcut command with bash alias

投稿日:


Abstract

Hello everyone it’s me candle.
I will introduce easy operation of the docker command.
Of course, I just created it thinking that it was useful, so please change it for much more useful.


Precondition

You use bash. ( Even though you use zsh or csh or something else, you edit a bit, it will work well)
You use docker

The list of alias

Open the .bash_profile in the home dicretory and write this.

# stop the running containers. You would pass the running container ids.
# ex) dcstop 5c07dab43333 30jfeodd
function dcstop(){
  docker stop $@
}

# stop all containers
alias dcstopa='docker stop $(docker ps -a -q)'

# remove the stopped containers. You would pass the stopped container ids.
# ex) dcrm 5c07dab43333 30jfeodd999
function dcrm(){
  docker rm $@
}

# remove all stopped containers
alias dcrma='docker rm $(docker ps -qf "status=exited") $(docker ps -qf "status=created")'

# stop and remove all containers
alias dcdel='dcstopa && dcrma'

# show running containers
alias dcps='docker ps'

# show all containers
alias dcpsa='docker ps -a'

# show stopped containers
alias dcpss='docker ps -f "status=exited"'

# docker-compose up
alias dcup='docker-compose up -d'

# docker-compose down -v
alias dcdown='docker-compose down -v'

# show all docker images
alias dci='docker images'

# remove some images. You would pass the image ids.
# ex) dcrmi d266fc618ebc 37bf53c81f1c
function dcrmi(){
  docker rmi $@
}

# remove latest created images
function dcrmli(){
  dcrmi $(docker images -q | awk 'NR == 1 {print $0}')
}

# show all docker volulmes
alias dcvls='docker volume ls'

# remove some volumes. You would pass the volume names.
# ex) dcvrm php-fpm nginx 3452380
function dcvrm(){
  docker volume rm $@
}

# login to the running container. You would pass the running container id.
# ex) dcexec 5c07dab43333
function dcexec(){
  docker exec -t -i $1 /bin/bash
}

# show cotainer logs. You would pass the container id
# ex) dclogs 5c07dab43333
function dclogs(){
  docker logs $1
}

# watching cotainer logs. You would pass the container id
# ex) dctail 5c07dab43333
function dctail(){
  docker logs -f $1
}


Conclusion

If you have any opinion, I’d appreciate if you would comment it with a comment field.

スポンサードリンク

If you think this article is good, share it please

-プログラミング
-,

執筆者:


comment

Your email address will not be published. Required fields are marked *

関連記事

Remove or allow the html tag with javascript + React and take measures against XSS

Abstract Hello everyone it’s me candle. In this time, we will write a program which displays only the permitted html tags by React and delete other tags. Notice, displaying originally html contents, it may has a security risk such as XSS. First of all, I am not a security expert, so there is a possibility of a bug in the code. Of course, I check it and test it as long as I do. If you find any vulnerabilities in the code, it would be helpful if you point out it in the post comment form. Condition Nothing Preparation of …

Create the simplest drop down menu in React

Abstract Hello everyone it’s me candle. In this time we will make a most simple drop down menu. Condition Knowledge of react Preparation We create a react project with the below command. create-react-app hello-menu Open src/App.js and write this. import React, { Component } from 'react' class App extends Component { render() { return ( <div> <p>hello menu</p> </div> ) } } export default App Create a components directory in the src directory. mkdir src/components Create a DropDownMenu.js file in the src/components directory. touch src/components/DropDownMenu.js Now on ready. Create a Drop down menu Open the src/components/DropDownMenu.js and write these. import …

React creates dummy data using Faker.js

Abstract Hello everyone it’s me candle. Let’s try to use Faker.js in React. I think that there are various purposes for using Faker.js. In many cases you will use it for testing, but this time I’d like to create a dummy react state using Faker.js. Condition You have a basic react skill create-react-app was installed Create new project First of all, create a react project. Execute the below command in your favorite directory and create a new react project. create-react-app faker-demo cd faker-demo Installation of faker Install faker with this coommand. yarn add –dev faker it’s over. Generate dummy data …

Create plantUML with emacs using plantuml-mode

Autumn leaves on wood table Abstract Hello everyone it’s me candle. In this time, we will introduce plantuml-mode of emacs supporting plantUML. plantuml-mode has three functions. Syntax highlight Autocomplete Display UML preview There are plenty of settings, so let’s do it patiently. Precondition You had plantuml command I installed plantuml with brew. but it is ok you prepare jar file. If you don’t have it yet, please refer to here. Build PlantUML environment on Mac using brew Install plantuml-mode The latest version of plant-mode is not yet registered in el-get packages, so we will get it from github directly. For …

React Native slows down when debugging on Google Chrome

English 日本語 Abstract Hello everybody, It’s candle. This time, we will solve the problem that using simulator is going to slow down when debugging on the Google Chrome Anyway, It is solved in a simple way. we use Chromium instead of Google Chrome. Premise React development environment has been established


I work in the venture company as a CTO. I start to write program in University, first I learned java, C++ and PHP. In the company, I'm developing web services by Rails. I do like to automation.